Digits
n Data
Netflix SQL Interview Question 05

Most
Watched
Show

Find the show with the highest number of views.

Schema

Table
Setup

Column NameTypeDescription
activity_idintegerWatch activity identifier.
user_idintegerUser identifier.
show_idintegerShow identifier.
devicevarcharViewing device.

Sample Data

Input
Output

Sample Input: watching_activity
activity_iduser_idshow_iddevice
110110TV
210220Mobile
310310TV
410410Laptop
510530TV
610620Mobile
710710TV
810820Tablet
910930TV
Expected Output
show_idviews
104

SQL Editor

Run
Query

postgresql
Waiting for query

show_idviews
104

Hints

Unlock
Clues

Hint 01: Each activity row is a view.
Hint 02: COUNT(*) by show_id.
Hint 03: Order descending and keep one row.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  show_id,
  COUNT(*) AS views
FROM watching_activity
GROUP BY show_id
ORDER BY views DESC
LIMIT 1;

Explanation

Step By
Step

01

Group watch activity by show_id.

02

Count rows in each group as views.

03

Return the show with the highest count.

Related Questions

Keep
Solving