Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
30-Day Retention by Channel
00:00
5 left

30-Day Retention by Channel

MediumSQL · PostgreSQL

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
Interviewer

Your question is 30-Day Retention by Channel. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.