Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Retention Rate for a Series

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

Your question is Retention Rate for a Series. 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 wants to measure whether viewers return to watch the same series after their initial viewing. Write a PostgreSQL query to calculate the 30-day retention rate for users who first watched series 101, The Peripheral, during January 2025.

Requirements

  1. Define the cohort as distinct users whose first qualifying view of series 101 occurred from 2025-01-01 through 2025-01-31.
  2. Count a user as retained if they watched series 101 again more than 0 and no more than 30 days after their first qualifying view.
  3. Return the cohort size, retained-user count, and retention rate as a percentage rounded to two decimal places.
  4. Prevent multiple follow-up views from counting a user more than once.

Schema

users
ColumnTypeDescription
user_idPKINTPrime Video user identifier
regionVARCHAR(30)User region
series
ColumnTypeDescription
series_idPKINTSeries identifier
titleVARCHAR(150)Series title
genreVARCHAR(50)Series genre
watch_events
ColumnTypeDescription
event_idPKINTViewing event identifier
user_idINTViewer identifier referencing users
series_idINTWatched series identifier referencing series
watched_atTIMESTAMPTime of the viewing event
watch_secondsINTNumber of seconds watched
Tablesusersserieswatch_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results