Moving average over 2 months: revenue, paid, since May 2025
Instructions
Consider orders with the status 'paid' created on or after May 1, 2025. For each calendar month (month is the first day of the month) compute value: the month's revenue, the sum of quantity * order_items.price over the items of these orders. Then output the moving average of value over the last 2 consecutive months, including the current one: for the first months of the period, where there are not enough previous months, average only the available ones. Do not output months without orders. Columns: month, value, moving_avg (rounded to 2 decimal places). Sort by month ascending.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
order_items.→order_id orders.id - N:1Many-to-one
order_items.→product_id products.id - N:1Many-to-one
orders.→customer_id customers.id - N:1Many-to-one
products.→category_id categories.id
Table data
Select a table in the diagram or list to view its rows.