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 | 4968 | 327 |
| 10 | 5156 | 330 |
| 9 | 5017 | 326 |
| 8 | 6084 | 400 |
| 7 | 6728 | 398 |
| 6 | 6472 | 400 |
| 5 | 5995 | 398 |
| 4 | 5761 | 474 |
| 3 | 5197 | 477 |
| 2 | 4098 | 466 |
| 1 | 3076 | 446 |
| 0 | 2061 | 410 |
holds on the current window