First-Order Cohorts
A cohort is the set of customers whose first order (earliest order_date) was in the same month. For cohorts from 2025-01 to 2025-12 return cohort (like '2025-03'), customers (how many customers started that month), repeaters (how many of them have more than one order in total) and repeat_percent (repeaters as a percentage of customers, rounded to 1 decimal). Sort by cohort.
Hint 1
One row per customer first: their first order date and their number of orders.
Reference solution
WITH per_customer AS (
SELECT customer_id, MIN(order_date) AS first_date, COUNT(*) AS orders
FROM orders
GROUP BY customer_id
)
SELECT STRFTIME('%Y-%m', first_date) AS cohort,
COUNT(*) AS customers,
SUM(CASE WHEN orders > 1 THEN 1 ELSE 0 END) AS repeaters,
ROUND(100.0 * SUM(CASE WHEN orders > 1 THEN 1 ELSE 0 END) / COUNT(*), 1) AS repeat_percent
FROM per_customer
WHERE first_date BETWEEN '2025-01-01' AND '2025-12-31'
GROUP BY STRFTIME('%Y-%m', first_date)
ORDER BY cohort;
The key step is to reduce orders to customers first (MIN(order_date) and COUNT(*) per customer), and only then group customers by their first month. Cohort analysis answers "do the customers we won in March behave differently from those we won in June?", and it is the foundation of retention reports. Note the pattern: a first level of aggregation (per customer), then a second (per cohort).