runtime
41 / 88

task Cohorts & retention · hard

Next-month retention by signup cohort

Group shoppers into cohorts by signup month. A shopper is retained if they placed a non-cancelled order in the calendar month after their signup month. Return cohort_month, cohort_size, retained and retention_pct.

what to return

Columns
cohort_monthcohort_sizeretainedretention_pct in this order
Rows
2 rows · any order
Watch for
cohort_month is YYYY-MM; cohort_size counts every shopper who signed up that month, even those who never ordered.
Only include cohorts whose following month ends on or before 2025-03-31 (later months aren't fully observed).
retention_pct is 0–100 with 2 decimals.
Skill
Build a cohort retention table with a maturity rule. Refresher: Dates & monthly analysis →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result2 rows · any order
cohort_monthcohort_sizeretainedretention_pct
2025-016466.67
2025-024375

all 2 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

shoppers5 columns · 17 rows
idinteger · keynametextemailtextregiontextsignup_datetext
1Ana Ruizana@harbor.testWest2025-01-03
2Ben Okaforben@harbor.testEast2025-01-05
3Chloe Parkchloe@harbor.testWest2025-01-09
4Dmitri Volkovdmitri@harbor.testNorth2025-01-14
5Esi MensahNULLSouth2025-01-20

showing 5 of 17 rows

sales_orders5 columns · 33 rows
idinteger · keyshopper_idinteger → shoppersorder_datetextstatustextdelivered_datetext
10112025-01-04delivered2025-01-08
10222025-01-06delivered2025-01-07
10312025-01-15delivered2025-01-20
10432025-01-18cancelledNULL
10542025-01-22delivered2025-01-31

showing 5 of 33 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.