Every language
1 linguagens, copy-ready. One at a time with syntax highlighting, or all inline.
SQLSQLrunnable
SELECT
day,
amount,
SUM(amount) OVER (
ORDER BY day
ROWS UNBOUNDED PRECEDING
) AS running_total
FROM daily_sales
ORDER BY day;Try it in the playground: add a duplicate day and watch the RANGE default give both rows the same total; ROWS fixes the accumulation. Moving 7-day window: ROWS BETWEEN 6 PRECEDING AND CURRENT ROW.