← All SQL interview questions

Three-day moving average of daily orders

MediumWindow FunctionsOracleWalmart

An operations dashboard smooths daily order volume with a 3-day moving average.

From daily_orders, return order_day, orders_count and moving_avg_3d (average of the current day and the two previous days, rounded to 2 decimals). Only return days for which three full days of data exist, so the first two days are excluded. Order by order_day.

Sample data

Table: daily_orders

10 row(s) · showing first 8

order_dayDATEorders_countINT
2026-10-15120
2026-10-16135
2026-10-17128
2026-10-18150
2026-10-19142
2026-10-20160
2026-10-21155
2026-10-22170