SQL Retention Analysis
The same cohort framing as before, now asking 'how many are still with us' instead of 'how many left.'
What & Why
Retention analysis usually means the same cohort-grouped query as churn analysis, just reading the "still active" count instead of the "churned" count — same data, different framing for the same conversation.
See How It Works
BUSINESS QUESTION
Growth wants retention percentages for every cohort month and period.
| cohort_month | period_number | users | retained |
|---|---|---|---|
| 2024-01-01 | 0 | 420 | 420 |
| 2024-01-01 | 1 | 420 | 268 |
| 2024-01-01 | 2 | 420 | 214 |
| 2024-02-01 | 0 | 510 | 510 |
EXAMPLE QUERY
SELECT
cohort_month,
period_number,
users AS cohort_users,
retained,
ROUND(100.0 * retained / NULLIF(users, 0), 2) AS retention_rate
FROM growth.cohort_retention
ORDER BY cohort_month, period_number;RESULT — retention by cohort period
| cohort_month | period_number | cohort_users | retained | retention_rate |
|---|---|---|---|---|
| 2024-01-01 | 0 | 420 | 420 | 100.00 |
| 2024-01-01 | 1 | 420 | 268 | 63.81 |
| 2024-01-01 | 2 | 420 | 214 | 50.95 |
| 2024-02-01 | 0 | 510 | 510 | 100.00 |
The result uses the same real cohort rows shown in the source table.
This lesson's practice is part of Pro.
Sign up free to try it on a real business scenario