Mastering SQL Window Functions

By Tech7 Team

Window functions perform calculations across a set of rows related to the current row.

ROW_NUMBER()

[sql] SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) as rank FROM employees; [/sql]

PARTITION BY

[sql] SELECT department, name, salary, AVG(salary) OVER (PARTITION BY department) as dept_avg FROM employees; [/sql]