Alright. Of course, you can add a
WHERE clause just as you do in any other query:
salary - AVG(salary) OVER()
WHERE department_id = 1;
Now, we only calculate the salaries in the department with
id = 1. Two exercises ago, we said that
OVER() means 'for all rows in the query result'. This 'in the query result' part is very important – window functions work only on the rows returned by the query.
Here, this means we'll get the salary of each IT department employee and the average salary in that department, and not in the entire company.That's a very important rule which you need to remember. Window functions are always executed AFTER the
WHERE clause, so they work on whatever they find as the result.