Download answer_key/kpis/club_mrr.sql from misatadata/pepperwind: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/misatadata/pepperwind/resolve/main/answer_key/kpis/club_mrr.sql
- Command line
-
hf download hf://datasets/misatadata/pepperwind/answer_key/kpis/club_mrr.sql
-
curl -L -o club_mrr.sql https://huggingface.co/datasets/misatadata/pepperwind/resolve/main/answer_key/kpis/club_mrr.sql
1.42 kB
| -- Club MRR at each month's end, by currency | |
| -- Paid-for (not gift) Club subscriptions live at the month's end, each at the net amount of the invoice line covering that instant (the latest invoice when two cover it), an annual plan's over twelve; in each currency's major units. | |
| 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)), s AS (SELECT s.subscription_id, s.interval, s.ended_at, upper(p.currency) AS cur FROM billing.subscription s JOIN billing.price p USING (price_id) WHERE NOT s.is_gift), l AS (SELECT i.subscription_id, i.invoice_id, i.created, l.period_start, l.period_end, sum(l.amount - coalesce(l.discount_amount, 0)) AS net FROM billing.invoice i JOIN billing.invoice_line l USING (invoice_id) WHERE i.subscription_id IS NOT NULL AND i.status <> 'void' GROUP BY 1, 2, 3, 4, 5), c AS (SELECT m.month, s.cur, s.subscription_id, CASE WHEN s.interval = 'year' THEN l.net / 12.0 ELSE l.net END / 100.0 AS mrr FROM m JOIN l ON l.period_start < m.t AND l.period_end >= m.t JOIN s ON s.subscription_id = l.subscription_id AND (s.ended_at IS NULL OR s.ended_at >= m.t) QUALIFY row_number() OVER (PARTITION BY m.month, s.subscription_id ORDER BY l.created DESC, l.invoice_id DESC) = 1) SELECT month, cur AS grp, sum(mrr) AS value, count(*) AS subscriptions FROM c GROUP BY 1, 2 ORDER BY 1, 2 | |