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 | 5089 | 336 |
| 10 | 5287 | 339 |
| 9 | 5121 | 334 |
| 8 | 6238 | 411 |
| 7 | 6895 | 409 |
| 6 | 6676 | 411 |
| 5 | 6159 | 409 |
| 4 | 5881 | 486 |
| 3 | 5282 | 486 |
| 2 | 4198 | 477 |
| 1 | 3142 | 456 |
| 0 | 2122 | 420 |
holds on the current window