orders(order_id, ordered_at, net_revenue)
For each of the twelve months of 2026, return revenue and the percent change from the month before it.
Months with no orders still appear, with revenue 0. January has no previous
month in range, and a month whose predecessor earned 0 has no meaningful
growth, so both get NULL.
Return month as 'YYYY-MM', revenue and mom_growth_pct rounded to two
decimals, ordered by month.
LAG over a grouped orders table would skip the empty months and compare
January to March, so the twelve months have to be generated first.
Tables
orders
order_id ordered_at net_revenue
-------- ---------- -----------
1 2026-01-10 100.00
2 2026-01-20 200.00
3 2026-02-05 150.00
4 2026-04-01 300.00
5 2026-12-31 50.00
Expected result
month revenue mom_growth_pct
------- ------- --------------
2026-01 300.00 NULL
2026-02 150.00 -50.00
2026-03 0.00 -100.00
2026-04 300.00 NULL
2026-05 0.00 -100.00
2026-06 0.00 NULL
2026-07 0.00 NULL
2026-08 0.00 NULL
... 4 more row(s)