Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Rolling 30-Day Retention Query
00:00
5 left

Rolling 30-Day Retention Query

HardSQL · PostgreSQL

Problem

EvenUp's marketing team wants to compare how effectively acquisition channels drive early customer engagement. Using customer acquisition records and subsequent activity events, calculate 30-day retention for each acquisition-date and channel cohort.

Assume a customer is retained when they generate at least one activity event strictly after acquisition and before 30 days have elapsed. Include cohorts with zero retained customers, and label missing acquisition channels as Unknown.

Requirements

  1. Return the acquisition date, acquisition channel, cohort size, retained customer count, and retention rate.
  2. Count each customer at most once, even if they have multiple activity events.
  3. Use a LEFT JOIN so cohorts with no retained customers remain in the output.
  4. Exclude events exactly 30 days after acquisition.
  5. Order results by acquisition channel and acquisition date.

Schema

customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
acquired_atTIMESTAMPTZTimestamp when the customer was acquired
acquisition_channelVARCHAR(50)Marketing channel credited with acquisition
customer_events
ColumnTypeDescription
event_idPKINTEGERUnique activity event identifier
customer_idINTEGERCustomer associated with the event
event_atTIMESTAMPTZTimestamp when the activity occurred
event_typeVARCHAR(50)Type of customer activity
Tablescustomerscustomer_events
Interviewer

Your question is Rolling 30-Day Retention Query. Start with the requirements and the two 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.