Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Genres With SQL Windows
00:00
5 left

Top Genres With SQL Windows

MediumSQL · PostgreSQL

Problem

Given a table of user streaming sessions, write a SQL query using window functions to find the top three most-watched genres for each user over the last 30 days.

Use CURRENT_DATE as the reference date. Sum watch minutes across sessions for the same user and genre. Exclude sessions without a genre. Return no more than three genres per user.

Output

  1. One row per included user and genre, with user_id, genre, total_watch_minutes, and genre_rank.
  2. Include each user's three highest totals, ordered by user_id, genre_rank, and alphabetically by genre for deterministic ties.

Schema

streaming_sessions
ColumnTypeDescription
session_idPKINTUnique streaming session identifier
user_idINTIdentifier of the streaming user
genreVARCHAR(50)Content genre watched during the session
watch_minutesINTNumber of minutes watched in the session
session_startTIMESTAMPTimestamp when the session started
Tablesstreaming_sessions
Interviewer

Your question is Top Genres With SQL Windows. Start with the requirements and the one table 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.