A subscription is active in a month if `start_date` <= the month's last day AND (`end_date` IS NULL OR `end_date` >= the month's first day). For EVERY month from 2026-01 to 2026-06 (inclusive, even months with no active subscription) return `month` ('YYYY-MM'), `active_subs`, `mrr` = sum of `monthly_fee` of active subscriptions (ROUND 2, 0 when none). Order by `month`.
| Column | Type |
|---|---|
| sub_id | INTEGER |
| customer_id | INTEGER |
| plan | TEXT |
| monthly_fee | REAL |
| start_date | DATE |
| end_date | DATE |
| sub_id | customer_id | plan | monthly_fee | start_date | end_date |
|---|---|---|---|---|---|
| 1 | 101 | Photography | 20.99 | 2026-01-15 | NULL |
| 2 | 102 | Acrobat Pro | 15 | 2025-11-01 | 2026-02-10 |
| 3 | 103 | Express | 9.99 | 2026-03-01 | 2026-03-31 |
| 4 | 104 | All Apps | 54.99 | 2026-05-20 | NULL |
| 5 | 105 | Photography | 20.99 | 2026-07-01 | NULL |
| month | active_subs | mrr |
|---|---|---|
| 2026-01 | 2 | 35.99 |
| 2026-02 | 2 | 35.99 |
| 2026-03 | 2 | 30.98 |
| 2026-04 | 1 | 20.99 |
| 2026-05 | 2 | 75.98 |
| 2026-06 | 2 | 75.98 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ 90th Percentile Daily Sales by Region · Merge Overlapping License Periods ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.