Digits
n Data
Netflix SQL Interview Question 06

Genre
Popularity

Find the most popular genre based on total watch time.

Schema

Table
Setup

Column NameTypeDescription
content_idintegerContent identifier.
genrevarcharGenre name.
Column NameTypeDescription
content_idintegerWatched content identifier.
hours_watcheddecimalWatch duration.

Sample Data

Input
Output

Sample Input: content
content_idgenre
1Drama
2Comedy
3Drama
4Action
Sample Input: watching_activity
content_idhours_watched
12.0
21.5
33.0
42.5
11.0
22.0
32.5
41.5
Expected Output
genretotal_hours
Drama8.5

SQL Editor

Run
Query

postgresql
Waiting for query

genretotal_hours
Drama8.5

Hints

Unlock
Clues

Hint 01: Genre lives in content, hours live in watching_activity.
Hint 02: Join by content_id.
Hint 03: Group by genre and SUM(hours_watched).

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
  c.genre,
  SUM(w.hours_watched) AS total_hours
FROM watching_activity w
JOIN content c
  ON w.content_id = c.content_id
GROUP BY c.genre
ORDER BY total_hours DESC
LIMIT 1;

Explanation

Step By
Step

01

Attach each watch row to its content genre.

02

Sum watch time for every genre.

03

Sort totals descending and return the top genre.

Related Questions

Keep
Solving