Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 5 Shows Per Region

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

Your question is Top 5 Shows Per Region. Start with the requirements and the three 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

Prime Video's content analytics team wants to compare show engagement across viewer regions. Write a PostgreSQL query that identifies the top five shows in each region by total positive watch time.

Requirements

  1. Join viewing events to the corresponding Prime Video regions and shows.
  2. Aggregate watch_minutes for each region and show, ignoring null or non-positive values.
  3. Use a window function to rank shows independently within each region.
  4. Return only the top five shows per region, ordered by region and rank. Break ties deterministically using show_id.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique region identifier
region_codeVARCHAR(10)Short region code
region_nameVARCHAR(100)Display name of the region
shows
ColumnTypeDescription
show_idPKINTUnique show identifier
show_titleVARCHAR(150)Prime Video show title
genreVARCHAR(50)Show genre
viewing_events
ColumnTypeDescription
event_idPKINTUnique viewing event identifier
region_idINTReferenced region
show_idINTReferenced show
watch_minutesINTMinutes watched during the event
Tablesregionsshowsviewing_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results