Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Write a query that reconstructs monthly revenue movement by separating new, expansion, contraction, and churn amounts into a readable waterfall.
Result columns · in this order
event_monthnew_revenueexpansion_revenuecontraction_revenuechurn_revenuenet_revenue_changeHow to approach it
Start with one CTE that groups monthly movements, then project net revenue change from the named movement columns.
Sample input
| account_id | event_month | movement_type | amount |
|---|---|---|---|
| 201 | 2026-01 | new | 1200 |
| 202 | 2026-01 | new | 800 |
| 201 | 2026-02 | expansion | 300 |
| 202 | 2026-02 | contraction | -150 |
| 203 | 2026-03 | churn | -500 |
5 rows — all rows shown.
Expected output
| event_month | new_revenue | expansion_revenue | contraction_revenue | churn_revenue | net_revenue_change |
|---|---|---|---|---|---|
| 2026-01 | 2000 | 0 | 0 | 0 | 2000 |
| 2026-02 | 500 | 300 | -150 | 0 | 650 |
| 2026-03 | 0 | 0 | 0 | -500 | -500 |
3 rows — all rows shown.
Constraints
Preserve the sign of contraction and churn movements, keep each movement type visible, and return one row per month ordered chronologically.
Expected skills
Conditional aggregation, clear CTE naming, financial sign handling, and explaining tradeoffs in revenue movement logic.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.