Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL With Constraints and Joins
00:00
5 left

SQL With Constraints and Joins

MediumSQL · PostgreSQL

Problem

Netflix wants to compare engagement across movie genres using viewing-session data. Write a PostgreSQL query that joins viewing sessions to title metadata and calculates the average watch time for qualifying sessions.

Requirements

  1. Join viewing_sessions to titles using title_id.
  2. Include only completed movie sessions from calendar year 2025 with at least 10 minutes watched.
  3. Return each genre, the number of qualifying sessions, and the average minutes watched, rounded to two decimal places.
  4. Keep only genres with at least two qualifying sessions and order by average watch time from highest to lowest.

Schema

titles
ColumnTypeDescription
title_idPKINTEGERUnique Netflix title identifier
title_nameVARCHAR(150)Name of the title
genreVARCHAR(50)Primary title genre
content_typeVARCHAR(20)Whether the title is a Movie or Series
viewing_sessions
ColumnTypeDescription
session_idPKINTEGERUnique viewing session identifier
title_idINTEGERReferences titles.title_id
profile_idINTEGERNetflix profile identifier
watched_atDATEDate of the viewing session
minutes_watchedNUMERIC(8,2)Minutes watched during the session
session_statusVARCHAR(20)Session completion status
Tablestitlesviewing_sessions
Interviewer

Your question is SQL With Constraints and Joins. 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.