Chapter 9 · Interview Level
43. Monthly Cohort Retention Rate
Hard40 XPE-Commerce
Calculate monthly retention rates for customer cohorts. A cohort is defined by the month of a customer's first order. For each cohort, determine what percentage of customers placed an order in subsequent months (month 0, 1, 2, etc.). months_since_first counts calendar months (January to March = 2). Return cohort_month, months_since_first, active_customers, and retention_pct (rounded to 1 decimal). 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.