Window Functions

PARTITION BY Clause & Window Definition: Mistakes

SELECT dept, AVG(salary) OVER (PARTITION BY dept) FROM employees; CREATE INDEX idx_dept ON employees(dept); SELECT name, dept, salary, AVG(salary) OVER (PARTITI

SELECT dept, AVG(salary) OVER (PARTITION BY dept) FROM employees;

CREATE INDEX idx_dept ON employees(dept); SELECT name, dept, salary, AVG(salary) OVER (PARTITION BY dept) as dept_avg FROM employees;

Two mistakes: no index on partition column causes poor performance, and missing individual columns loses important detail that PARTITION BY is designed to preserve.

Always index PARTITION BY columns and include individual row details

High

Query runs slowly, missing employee details