Month Over Month Revenue Growth

Return one row per calendar month in which at least one order was placed, with:

  • month — the first day of the month, as a date
  • revenue — the total amount of that month's orders
  • prev_revenue — the revenue of the immediately preceding month that appears in this result, or NULL for the first month
  • change — revenue - prev_revenue, or NULL for the first month

Order by month ascending.

Expected output


month      | revenue | prev_revenue | change
-----------+---------+--------------+--------
2024-01-01 | 800.00  | NULL         | NULL
2024-02-01 | 400.00  | 800.00       | -400.00
2024-04-01 | 1200.00 | 400.00       | 800.00
2024-05-01 | 1000.00 | 1200.00      | -200.00
PostgreSQL

Press Run to start the SQL engine.

SensAI
Beta
Tap the mic to stop voice mode