How can we compute rankings or window metrics independently within each department?
PARTITION BY divides the result set into window partitions before applying analytical functions.
Ranking employees within their department, calculating customer-level metrics in event logs.
SELECT name,
department,
salary,
RANK() OVER (
PARTITION BY department
ORDER BY salary DESC
) AS department_rank
FROM employees;Practice typing production-grade SQL code for SQL PARTITION BY.