pepperwind / answer_key /kpis /club_active_subscriptions.sql
rasinmuhammed's picture
Pepperwind Trading Co. preview, version 1.0
27ec678 verified
Raw History Blame Contribute Delete
489 Bytes
-- Club subscriptions live at each month's end
-- Paid-for (not gift) subscriptions begun before the month's end and not ended by then.
WITH m AS (SELECT strftime(range, '%Y-%m') AS month, range AS t0, range + INTERVAL 1 MONTH AS t FROM range(TIMESTAMP '2023-10-01', TIMESTAMP '2026-10-01', INTERVAL 1 MONTH)) SELECT m.month, count(*) AS value FROM m JOIN billing.subscription x ON x.start_date < m.t AND (x.ended_at IS NULL OR x.ended_at >= m.t) AND (NOT x.is_gift) GROUP BY 1 ORDER BY 1