Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Subscriber Retention Over 90 Days

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

Your question is Subscriber Retention Over 90 Days. 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

Disney+ Hotstar wants to measure whether new paid subscribers remain subscribed at least 90 days after their first paid subscription begins. Write a PostgreSQL query that produces retention metrics by signup cohort and acquisition channel.

Requirements

  1. Consider only each user's first paid subscription. Exclude free-trial plans and later paid subscriptions.
  2. Define a subscriber as retained when their subscription end date is at least 90 days after the start date. A NULL end date represents an ongoing subscription and counts as retained.
  3. Return the cohort month, acquisition channel, cohort size, retained subscriber count, and retention rate as a percentage rounded to two decimal places.
  4. Rank acquisition channels within each cohort by retention rate in descending order, using a window function.
  5. Sort the final result by cohort month, rank, and acquisition channel.

Schema

users
ColumnTypeDescription
user_idPKINTUnique subscriber identifier
signup_dateDATEDate the user registered
acquisition_channelVARCHAR(40)Marketing channel that acquired the user
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription record identifier
user_idINTReferences users.user_id
plan_idINTReferences plans.plan_id
start_dateDATEDate the subscription began
end_dateDATEDate the subscription ended, or NULL when ongoing
plans
ColumnTypeDescription
plan_idPKINTUnique plan identifier
plan_nameVARCHAR(60)Display name of the subscription plan
plan_tierVARCHAR(20)Plan tier such as Mobile, Super, Premium, or Trial
is_paidBOOLEANIndicates whether the plan is paid
Tablesuserssubscriptionsplans
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results