mrr_snapshots has one row per customer per month (month = first day of the month) while they pay; a missing row means MRR 0 for that month, and a row may also hold 0 explicitly. Use every calendar month from the earliest to the latest month in the table (even a month with no rows at all). Compare each customer's MRR with the previous calendar month: new = previous 0 and current > 0 (current); expansion = current > previous > 0 (current - previous); contraction = 0 < current < previous (previous - current); churned = previous > 0 and current 0 (previous). Return month ('YYYY-MM'), new_mrr, expansion_mrr, contraction_mrr, churned_mrr (ROUND 2) for every month except the first. Order by month.
| Column | Type |
|---|---|
| customer_id | TEXT |
| month | DATE |
| mrr | REAL |
| customer_id | month | mrr |
|---|---|---|
| cA | 2026-01-01 | 100 |
| cA | 2026-02-01 | 150 |
| cA | 2026-03-01 | 150 |
| cB | 2026-01-01 | 200 |
| cB | 2026-02-01 | 120 |
| cC | 2026-02-01 | 80 |
| cC | 2026-03-01 | 100 |
| cD | 2026-01-01 | 50 |
| month | new_mrr | expansion_mrr | contraction_mrr | churned_mrr |
|---|---|---|---|---|
| 2026-02 | 80 | 50 | 80 | 50 |
| 2026-03 | 50 | 20 | 0 | 120 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Loan Delinquency Buckets · Bench Periods Between Project Allocations ›
{{ 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.