Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Genres by Demographic
00:00
5 left

Top Genres by Demographic

MediumSQL · PostgreSQL

Problem

Warner Bros. Discovery wants to compare viewing preferences across user demographic groups. Write a SQL query to find the three most-watched content genres for each demographic group during the 30-day reporting period ending on September 18, 2026.

Output

  1. Return one row per demographic and genre ranking, with columns demographic_group, genre, total_minutes, and genre_rank.
  2. Include only sessions in the reporting period, and exclude rows with a NULL demographic group or genre.
  3. Return up to three genres per demographic, ordered by total watched minutes descending. Break ties alphabetically by genre.
  4. Order the final result by demographic group and genre rank.

Schema

streaming_sessions
ColumnTypeDescription
session_idPKINTUnique streaming session identifier
user_idINTUser associated with the session
content_idINTContent watched during the session
session_startTIMESTAMPSession start timestamp
minutes_watchedINTMinutes watched during the session
users
ColumnTypeDescription
user_idPKINTUnique user identifier
demographic_groupVARCHAR(50)User demographic classification
content
ColumnTypeDescription
content_idPKINTUnique content identifier
content_titleVARCHAR(150)Title of the content
genreVARCHAR(50)Primary content genre
Tablesstreaming_sessionsuserscontent
Interviewer

Your question is Top Genres by Demographic. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.