Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Content by Watch Time

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Content by Watch Time. Start with the requirements and the two tables on the right.

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.

Problem

Disney+ Hotstar's Product Analytics team wants to identify the strongest-performing content in January 2026. Write a PostgreSQL query that ranks content within each content type using watch-time metrics.

Requirements

  1. Join the content catalog to viewing sessions and include only sessions from January 2026.
  2. Calculate total watch minutes and average completion percentage for each content item. Treat NULL watch minutes as zero.
  3. Use a window function to rank content separately within each content_type.
  4. Return the top two content items per content type, ordered by content type and rank.

Schema

content
ColumnTypeDescription
content_idPKINTEGERUnique content identifier
titleVARCHAR(150)Content title
content_typeVARCHAR(30)Content category
viewing_sessions
ColumnTypeDescription
session_idPKINTEGERUnique viewing session identifier
content_idINTEGERWatched content identifier
watched_atDATEDate of the viewing session
watch_minutesINTEGERMinutes watched in the session
completion_pctINTEGERPercentage of content completed
Tablescontentviewing_sessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results