Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Content by Unique Viewers

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

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

Paramount+ analytics needs a quarterly ranking of content performance. Write a PostgreSQL query that identifies the five content pieces with the most unique viewers during Q2 2025, from April 1 through June 30.

Requirements

  1. Join content_catalog with viewing_events using content_id.
  2. Include viewing events where viewed_at is on or after 2025-04-01 and before 2025-07-01.
  3. Count distinct non-null viewer_id values for each content piece.
  4. Return the top five results, ordered by unique viewers descending, with content_id ascending as a deterministic tie-breaker.

Schema

content_catalog
ColumnTypeDescription
content_idPKINTEGERUnique content identifier
titleVARCHAR(150)Paramount+ content title
content_typeVARCHAR(30)Movie, series, or special
release_dateDATEOriginal release date
genreVARCHAR(50)Primary genre
viewing_events
ColumnTypeDescription
event_idPKINTEGERUnique viewing event identifier
content_idINTEGERReferenced content identifier
viewer_idINTEGERViewer identifier
viewed_atTIMESTAMPViewing timestamp
surfaceVARCHAR(30)Paramount+ viewing surface
Tablescontent_catalogviewing_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results