Running revenue by month

easySQL~15 min · 4 tests · bitshop

Finance wants a cumulative revenue line: each month’s delivered revenue, plus the total so far.

Revenue for a line item is quantity * unit_price. Only count orders whose status is 'delivered'. A month is the calendar month of order_date; report it as a date on the first of the month (for example 2025-03-01).

Return one row per month that has delivered revenue:

column type meaning
month date first day of the month
revenue decimal delivered revenue in that month, rounded to 2 decimals
running_revenue decimal delivered revenue from the first month up to and including this one, rounded to 2 decimals

Months with no delivered orders don’t appear. Order matters: oldest month first.

Tables: orders, order_items.

Learn the ideaRead the lesson →
solution.sqlDuckDB · bitshop

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run