Average current row and previous two rows.
Section: Moving windows
3-row moving average
sql
sql
SELECT day,
revenue,
AVG(revenue) OVER (
ORDER BY day
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
) AS moving_avg_3
FROM daily_revenue;Explanation
A row-based moving average is stable when each row is one time bucket.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Moving windows