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

Top Genres by Region SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify the top 5 most-watched genres by region over the last quarter.

Use the Prime Video viewing data represented by the provided tables. Define the last quarter relative to the current date, and exclude records with missing regions or genres.

Output

  1. One row per qualifying region and genre, with columns region, genre, total_watch_minutes, and genre_rank.
  2. Return the five highest totals per region, breaking ties alphabetically by genre.
  3. Sort by region, then genre_rank, then genre.

Schema

viewing_events
ColumnTypeDescription
viewing_idPKINTUnique viewing event identifier
title_idINTViewed title identifier
regionVARCHAR(50)Viewer region
watched_atTIMESTAMPTimestamp when viewing occurred
watch_minutesINTMinutes watched in the event
titles
ColumnTypeDescription
title_idPKINTUnique title identifier
title_nameVARCHAR(200)Prime Video title name
title_genres
ColumnTypeDescription
title_idPKINTTitle identifier
genreVARCHAR(100)Genre assigned to the title
Tablesviewing_eventstitlestitle_genres
Interviewer

Your question is Top Genres by Region SQL. 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.