Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

30-Day Retention by Channel

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

Your question is 30-Day Retention by Channel. 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

NovaPlay wants to measure how well each acquisition channel retains new users after signup. Write a PostgreSQL query to calculate 30-day retention by acquisition channel.

A user is considered retained if they have at least one activity event on or after signup_date + 30 days and on or before signup_date + 60 days. Use each user's acquisition channel from the acquisitions table.

Requirements

  1. Return one row per acquisition channel.
  2. For each channel, calculate:
    • total signed-up users
    • retained users
    • 30-day retention rate as a percentage rounded to 2 decimals
  3. Include users even if they have no matching acquisition row; label those as 'Unknown'.
  4. Order results by retention rate descending, then channel name ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
signup_dateDATEDate the user signed up
countryVARCHAR(50)User country
acquisitions
ColumnTypeDescription
acquisition_idPKINTUnique acquisition record identifier
user_idINTUser tied to the acquisition record
channelVARCHAR(50)Acquisition channel
campaign_nameVARCHAR(100)Marketing campaign name
activity_events
ColumnTypeDescription
event_idPKINTUnique activity event identifier
user_idINTUser who generated the event
event_dateDATEDate of the activity event
event_typeVARCHAR(50)Type of user activity
Tablesusersacquisitionsactivity_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results