What does AVG(salary) OVER () do, and how is it different from GROUP BY?
EasyAn empty OVER computes the aggregate over every row of the result and attaches it to each row, without collapsing rows the way GROUP BY does.
SELECT name, department, salary,
AVG(salary) OVER () AS company_avg
FROM employees;
GROUP BY would collapse the table to one row (or one per department); the window version returns every employee with the company average alongside, so salary - AVG(salary) OVER () gives each person's distance from the average in one pass. Without the window you need a subquery or a join back to an aggregate. The window is computed after WHERE, so filtering to one department changes the average too.