Chapter 9 · Interview Level
36. Monthly Cohort Retention Analysis
Hard40 XPE-Commerce
Perform a cohort retention analysis. Define each customer's cohort as the month of their first order. For each cohort month and subsequent order month, count distinct customers. Show cohort_month, order_month, months_since_first (0, 1, 2...), and customer_count. Sort by cohort_month, then months_since_first.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.