Usage before voluntary cancel
WITH cancels AS (
SELECT s.account_id, e.at AS canceled_at
FROM subscription_events e
JOIN subscriptions s ON s.id = e.subscription_id
WHERE e.kind = 'cancel' AND e.reason = 'requested'
),
events AS (
SELECT c.account_id,
CAST((julianday(c.canceled_at) - julianday(a.at)) / 7 AS INTEGER) AS weeks_before
FROM app_events a
JOIN users u ON u.id = a.user_id
JOIN cancels c ON c.account_id = u.account_id
WHERE a.at < c.canceled_at
AND datetime(a.at) >= datetime(c.canceled_at, '-84 days')
)
SELECT weeks_before,
COUNT(*) AS events,
COUNT(DISTINCT account_id) AS accounts
FROM events
GROUP BY weeks_before
ORDER BY weeks_before DESC;View data table
| weeks_before | events | accounts |
|---|---|---|
| 11 | 3881 | 257 |
| 10 | 3808 | 257 |
| 9 | 3891 | 257 |
| 8 | 4389 | 320 |
| 7 | 4851 | 319 |
| 6 | 4738 | 319 |
| 5 | 4350 | 319 |
| 4 | 4063 | 402 |
| 3 | 4118 | 411 |
| 2 | 3219 | 411 |
| 1 | 2466 | 406 |
| 0 | 1643 | 393 |
holds on the current window