Amazon Prime finance teams monitor subscription health through monthly churn metrics. For each calendar month in the provided `subscription_months` calendar table, calculate: 1. `active_start`: The count of subscribers active at the beginning of the month (i.e. `start_date < month_start` and (`cancel_date IS NULL` OR `cancel_date >= month_start`)). 2. `cancelled_during`: The count of subscribers who cancelled their subscription during that month (i.e. `cancel_date >= month_start` AND `cancel_date <= month_end`). 3. `churn_rate`: The monthly cancellation percentage calculated as `ROUND(100.0 * cancelled_during / active_start, 2)`. If `active_start = 0`, report 0.00. Return `calendar_month` (e.g. '2025-01', '2025-02'), `active_start`, `cancelled_during`, and `churn_rate`. Order results chronologically by `calendar_month ASC`. Note: CTE support requires DuckDB / full SQL engine capabilities. This question is staged for the upcoming DuckDB browser engine.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.