SQL QuestSQL Interview Questions › Subqueries & CTEs

Signup Cohort Activation Within 30 Days

MediumFreeQuerying BasicsSubqueries & CTEsJoinsAggregation & Grouping

A cohort funnel: of the people who signed up each month, how many did anything within their first 30 days? A user is activated when they have at least one completed transaction with ts no more than 30 days after signup_date (julianday(ts) - julianday(signup_date) <= 30).

Group users by signup month (strftime('%Y-%m', signup_date)). Return cohort, users, activated and activation_pct (100.0 * activated / users, rounded to 1 decimal). Every cohort appears, even one with zero activated users. Order by cohort ascending.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

users

user_idsignup_datecountryhome_currencyplanplan_sincekyc_verified_atreferred_bybirth_year
12025-06-01IEEURstandard2025-06-012025-06-03 16:00:00NULL1972
22025-06-02FREURstandard2025-06-022025-06-04 16:00:00NULL1979
32025-06-03GBGBPstandard2025-06-032025-06-08 04:00:00NULL1977

transactions

txn_iduser_idtstypeamountcurrencyamount_gbpfee_gbpmerchant_categorymerchant_countrycounterparty_user_idstatusdecline_reason
112025-06-14 11:01:51fx_exchange32271.15JPY167.811.68NULLNULLNULLcompletedNULL
212025-06-14 11:17:45bill_payment59.53EUR50.60utilitiesIENULLcompletedNULL
372025-06-16 10:06:38card_payment122.27EUR103.930shoppingESNULLcompletedNULL

Expected output: cohort=2025-06, users=16, activated=14, activation_pct=87.5 ...

Hint

Build the activated set once in a CTE (SELECT DISTINCT user_id ... WHERE status='completed' AND julianday(ts) - julianday(signup_date) <= 30), then LEFT JOIN it to users so cohorts with nobody activated still show. COUNT(a.user_id) counts only the matches.

Concepts

SELECT CTE LEFT JOIN GROUP BY julianday COUNT CTE + Cohort Analysis

Practise the topic: SQL practice questions · CTE practice · JOIN practice · GROUP BY exercises

In these company practice sets

Revolut

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Department Roster with GROUP_CONCATMedium · FreeConsistent Director AnalysisMedium · FreeBelow Department AverageMedium · FreeHighest Total Salary Budget DepartmentMedium · FreeFare Imputation AnalysisMedium · FreeUNION ALL Dedup: Cross-Dataset SearchMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test