running total
A total that grows row by row, adding each row's value to the sum of all rows before it.
In more detail
SUM(x) OVER (ORDER BY key) computes it in one query. The ORDER BY inside OVER decides what counts as before, so it should be unique or ties will share a total.
Related terms
- window function — A calculation across a set of rows related to the current row that, unlike GROUP BY, keeps every input row in the answer.
- OVER — The clause that makes a function a window function and defines which rows it can see and in what order.
- window frame — The subset of a partition that a window calculation sees for each row, such as the current row and the one before it.
Taught in
- Window Functions: Replacing Application Loops — PostgreSQL, Indexing & Relational Data Modeling