All problems

Who's Exploring Beyond One Show?

mediumSQLGroupByHaving

StreamVerse has spent the quarter arguing about recommendations, and the content team wants a fact to argue from: how many subscribers actually reach for something new, rather than putting the same programme on again every evening?

The viewing log makes this less obvious than it sounds. It records one row per viewing session, so a subscriber who watched one show three times has three rows, and a subscriber who watched three different shows also has three rows. Counting rows cannot tell those two people apart, and they are precisely the two the team is trying to separate.

watch_events — one row per viewing session. show_id points at a row in the shows catalogue; watch_minutes is how long that session lasted.

id subscriber_id show_id watch_minutes watch_date
1 1 1 45 2023-05-01
2 1 5 60 2023-05-03
3 2 3 20 2023-05-02
4 3 2 55 2023-05-05
5 4 1 40 2023-05-06
6 4 4 70 2023-05-08
7 1 3 25 2023-05-10
8 3 5 50 2023-05-11
9 2 2 30 2023-05-12
10 5 4 65 2023-05-14

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning a single column, subscriber_id, holding every subscriber who has watched at least two different show_id values. Somebody who has watched the same show many times and nothing else does not qualify. Hand the ids back smallest first.

Example output — shape only, on invented ids.

subscriber_id
6
7
9

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…