How can we calculate how much an employee earns above or below the overall company average?
Subtracting global window aggregates (AVG() OVER ()) from row values computes instant variances.
Compensation variance reports, SLA latency deviations, anomaly scoring.
SELECT
name,
salary,
salary - AVG(salary) OVER () AS difference_from_average
FROM employees;Practice typing production-grade SQL code for Salary Difference.