Practice · medium · dataset: ecom
Monthly revenue change
Compare each month’s revenue with the previous month’s. Revenue is the sum of quantity times the
line’s unit_price for orders in that month.
Return month (the first day of the month), revenue, previous_revenue, and change (current
minus previous), with all money columns rounded to two decimals. Sort by month ascending.
The first month has no previous month, so its previous_revenue and change must be NULL.
Tables available
| Table | Columns |
|---|---|
orders |
order_id, customer_id, order_date, status, channel |
order_items |
order_id, product_id, quantity, unit_price |
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.