Aggregate Window Functions
You know SUM, AVG, COUNT as aggregate functions with GROUP BY. But they also work as window functions with OVER().
The key difference: GROUP BY collapses rows, OVER() keeps every row.
Running total:
Department average alongside each row:
Now you can compare each salary to the department average - without a subquery!
Count within partition:
This is one of the most powerful SQL patterns for analytics.
Check your understanding
How do you show the department average salary on every row without collapsing rows?
Examples run on the employees sample database. Open any of them in the playground to experiment.