7-Day Revenue Moving Average
Problem
**[Classic — asked at restaurant and retail companies]**
Compute a **7-day moving average of daily revenue**.
For each day, the average covers that day plus the 6 preceding days.
Return `rev_date`, `revenue`, and `moving_avg_7d` (rounded to 2 dp), ordered by date.
Tables
Example rows — the live problem includes the full dataset.
daily_revenue
| rev_date | revenue |
|---|
Expected output
Your answer should return 7 rows with the columns rev_date, revenue, moving_avg_7d.
Starter code (SQL)
SELECT *
FROM daily_revenue;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock