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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
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.

Output details

  • Treat DATE '2026-07-01' as today's date.
  • Interpret last quarter as the immediately preceding calendar quarter, including its start and excluding its end.
  • Preserve qualifying region-genre groups whose total watch minutes is NULL; do not otherwise special-case zero values.

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
Sign up free to run your codeLog inLn 1
Run your query to see results here.