Chapter 8 · Window Functions
23. 7-Day Moving Average of Order Amounts
Hard40 XPE-Commerce
Compute a 7-day moving average of daily order revenue. For each date, show the order_date, daily revenue, and the average of that day and the 6 previous days that had orders (a 7-row window). Round to 2 decimal places. Sort by order_date.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.