Databases · interactive
Window functions
GROUP BY squashes rows into one per group. A window function keeps every row and adds a value computed over related rows: its partition, in an order, over a frame. Click a row to see which rows its value came from.
SELECT rep, month, amount,
SUM(amount) OVER (PARTITION BY rep ORDER BY month)
FROM sales;| rep | month | amount | Running SUM |
|---|---|---|---|
| Ada | 1 | 300 | 300 |
| Ada | 2 | 500 | 800 |
| Ada | 3 | 200 | 1000 |
| Bo | 1 | 400 | 400 |
| Bo | 2 | 400 | 800 |
| Bo | 3 | 700 | 1500 |
Faded: other partitions. Shaded: rows that fed the selected value.
Row Bo, month 2: sum of Bo's months 1–2 = 800.
Function
Step 3 of 4 · read left to right
In production
Tools and technologies
Every modern SQL database supports window functions.
Not tied to one language — use these names when you search docs or design a system.