How can we calculate the exact monetary difference between consecutive employee salaries?
Subtracting LAG(salary) from the current salary measures the incremental step between sorted records.
Band gap analysis, pay step distribution, detecting compensation compression.
SELECT
name,
salary,
salary - LAG(salary) OVER (
ORDER BY salary
) AS salary_difference
FROM employees;Practice typing production-grade SQL code for Salary Change.