402. 7-Day Moving Average of Sales

Hard FinTech Time Series Analysis
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
locations
3 cols
departments
3 cols
employees
6 cols
orders
6 cols

Reference Solution

Expected SQL
SELECT order_date, SUM(amount) AS daily_sales, AVG(SUM(amount)) OVER (ORDER BY order_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS moving_avg_7d FROM orders GROUP BY order_date;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.