A window function adds a value to each row
GROUP BY collapses rows into one line per group. A window function works out a value too, but leaves every row where it is and adds the answer as an extra column. The OVER clause is what makes it a window function, and the ORDER BY inside OVER decides the order the rows are read in.
A tiny example
In plain English: Show me every student's name with their place in the score ranking.
SELECT name, RANK() OVER (ORDER BY score DESC) AS place
FROM students;What comes back
| name | place |
|---|---|
| Nia | 1 |
| Theo | 2 |
| Ravi | 3 |
Every student kept their own row, and the extra column shows each one's place by score.
Related SQL lessons
- A query can hold another query inside itA query can hold another query inside it
- EXISTS asks 'is there at least one?'EXISTS asks 'is there at least one?'
- SUM OVER (ORDER BY ...)SUM OVER (ORDER BY ...) is a running total
- WITH starts a common table expression (CTE)WITH starts a common table expression (CTE)
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