AdvancedGROUP BY & Aggregation
Cohort size by signup month
The query
SQL
SELECT
DATE_TRUNC('month', joined_at)::DATE AS cohort_month,
COUNT(*) AS cohort_size,
SUM(COUNT(*)) OVER (ORDER BY DATE_TRUNC('month', joined_at)) AS cumulative_customers
FROM customers
GROUP BY DATE_TRUNC('month', joined_at)
ORDER BY cohort_month;Note
“Cumulative count using running SUM window function over monthly groups.