Code assistant
Churn by plan
Conversation
Give me monthly churn by plan for this year.
10:02
AI
Here is a query that counts cancelled subscriptions against the ones active at the start of each month. It is on the right.
10:02Leave out trial accounts.
10:04Query
Postgres
churn_by_plan.sql
-- monthly churn by plan, paid accounts only
with months as (
select generate_series('2026-01-01'::date, '2026-10-01', '1 month') as month
)
select m.month,
s.plan,
count(*) filter (where s.cancelled_at >= m.month
and s.cancelled_at < m.month + interval '1 month') as cancelled,
count(*) filter (where s.started_at < m.month) as active
from months m
join subscriptions s on s.started_at < m.month + interval '1 month'
where s.trial = false
group by 1, 2
order by 1, 2;
Why it is fastThe filter on trial uses an index, and the series has only ten months.
Result
30 rows · 84 ms
| Month | Plan | Cancelled | Active | Churn |
|---|---|---|---|---|
| Jan | Starter | 18 | 420 | 4.3% |
| Jan | Growth | 7 | 260 | 2.7% |
| Jan | Business | 1 | 90 | 1.1% |
| Feb | Starter | 18 | 439 | 4.1% |
| Feb | Growth | 7 | 272 | 2.6% |
| Feb | Business | 1 | 94 | 1.1% |
| Mar | Starter | 19 | 458 | 4.1% |
| Mar | Growth | 8 | 283 | 2.8% |
| Mar | Business | 1 | 98 | 1.0% |
| Apr | Starter | 20 | 477 | 4.2% |
| Apr | Growth | 8 | 295 | 2.7% |
| Apr | Business | 2 | 102 | 2.0% |
| May | Starter | 21 | 496 | 4.2% |
| May | Growth | 8 | 307 | 2.6% |
| May | Business | 2 | 106 | 1.9% |
| Jun | Starter | 22 | 515 | 4.3% |
| Jun | Growth | 9 | 319 | 2.8% |
| Jun | Business | 2 | 110 | 1.8% |
| Jul | Starter | 22 | 533 | 4.1% |
| Jul | Growth | 9 | 330 | 2.7% |
| Jul | Business | 2 | 114 | 1.8% |
| Aug | Starter | 23 | 552 | 4.2% |
| Aug | Growth | 9 | 342 | 2.6% |
| Aug | Business | 2 | 118 | 1.7% |
| Sep | Starter | 24 | 571 | 4.2% |
| Sep | Growth | 10 | 354 | 2.8% |
| Sep | Business | 2 | 122 | 1.6% |
| Oct | Starter | 25 | 590 | 4.2% |
| Oct | Growth | 10 | 365 | 2.7% |
| Oct | Business | 2 | 126 | 1.6% |
| No results · Try other words or clear the filter. | ||||
No rows match your search.