Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Content by Watch Time
00:00
5 left

Top Content by Watch Time

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top Content by Watch Time. Start with the requirements and the two 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.