SUM OVER (ORDER BY ...) is a running total
Put an ORDER BY inside OVER and SUM stops being one grand total. As a window function it gives each row the total of everything up to and including that row, like the balance column on a bank statement. The last row holds the full total.
A tiny example
In plain English: Show me each term with the points added up from the first term through that one.
SELECT term, SUM(points) OVER (ORDER BY term) AS running
FROM results;What comes back
| term | running |
|---|---|
| Autumn | 10 |
| Spring | 25 |
| Winter | 45 |
Each row adds its own points to everything before it: 10, then 10 + 15, then 25 + 20.
Related SQL lessons
Ready for a break?
Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.
play today's sip