Write SQL for repeat churn
OpenAIData Scientist · Technical ScreenLast updated
This question evaluates proficiency in event-time analytics and cohort churn metric computation using SQL, focusing on correct identification of first qualifying events and aggregation by experimental variant.
Write a SQL query to measure the performance of a free-month promotion experiment.
Assume experiment_users already contains only users who were eligible for the experiment. Do not re-implement eligibility logic.
Tables:
experiment_users
user_idBIGINT -- primary keyvariantVARCHAR -- values:control,free_monthassigned_atTIMESTAMP -- experiment assignment time in UTC
subscription_events
user_idBIGINT -- foreign key toexperiment_users.user_idevent_tsTIMESTAMP -- event time in UTCevent_typeVARCHAR -- one ofsignup,free_trial_start,paid_start,cancel,reactivate
Business definitions:
eligible_users: distinct users inexperiment_users.signups_30d: users whose firstsignupafterassigned_atoccurs within 30 days of assignment.paid_converted_60d: users whose firstpaid_startafterassigned_atoccurs within 60 days of assignment.churned_90d_after_first_paid: among users with a firstpaid_start, count users who have at least onecancelevent within 90 days after that firstpaid_start.- A user may cancel, reactivate, and cancel again. Count the user at most once, using the first
cancelafter the firstpaid_start. Ignorecancelevents that happen before the firstpaid_start. - Use only each user's first qualifying
signupand first qualifyingpaid_startafter assignment.
Return one row per variant with these columns:
varianteligible_userssignups_30dpaid_converted_60dchurned_90d_after_first_paidchurn_rate_90d_after_first_paidwhere the denominator ispaid_converted_60d.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.