`daily_orders` may have missing days (no orders = no row) and occasionally two rows for the same day (add them up). For each restaurant build a complete calendar from its first to its last `order_date`, treating missing days as 0 orders. For every calendar day that has a FULL 7-day window inside that calendar (i.e. from the restaurant's 7th calendar day onward), compute the 7-day rolling average = (sum of orders for that day and the 6 previous days) / 7. Return `restaurant_id`, `order_date`, `rolling_7d_avg` (ROUND 2). Order by `restaurant_id`, `order_date`.
| Column | Type |
|---|---|
| restaurant_id | INTEGER |
| order_date | DATE |
| orders | INTEGER |
| restaurant_id | order_date | orders |
|---|---|---|
| 1 | 2026-09-01 | 10 |
| 1 | 2026-09-02 | 12 |
| 1 | 2026-09-04 | 8 |
| 1 | 2026-09-05 | 10 |
| 1 | 2026-09-06 | 6 |
| 1 | 2026-09-07 | 14 |
| 1 | 2026-09-08 | 7 |
| 1 | 2026-09-09 | 20 |
| restaurant_id | order_date | rolling_7d_avg |
|---|---|---|
| 1 | 2026-09-07 | 8.57 |
| 1 | 2026-09-08 | 8.14 |
| 1 | 2026-09-09 | 9.29 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ De-duplicate Burst Reviews · First Time a Wallet Goes Negative ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.