SQL · Pattern 10 — Window Functions
Window Aggregate
Performs aggregate calculations without GROUP BY.
Source data — Pattern 10: Window Functions
All queries run against the shared employees table (see schema.sql). This pattern introduces a sales table to demonstrate window functions including ranking, navigation, running totals, moving averages and window aggregates.


What it does
Performs aggregate calculations without GROUP BY.
Problem
Calculate department-wise average salary without grouping.
SELECT first_name,salary,
AVG(salary) OVER(PARTITION BY department_id) AS result
FROM employees;
Result
