Skip to main content
SQL • LESSON 155

Salary Change

How can we calculate the exact monetary difference between consecutive employee salaries?

Advanced3 Minutes1680 XP
🤔 THE QUESTION

How can we calculate the exact monetary difference between consecutive employee salaries?

💡 WHAT IS IT?

Subtracting LAG(salary) from the current salary measures the incremental step between sorted records.

🎯 WHAT IS IT USED FOR?

Band gap analysis, pay step distribution, detecting compensation compression.

💻 EXAMPLE
SELECT
name,
salary,
salary - LAG(salary) OVER (
    ORDER BY salary
) AS salary_difference
FROM employees;

🎯 Mission Objectives

Practice typing production-grade SQL code for Salary Change.

  • Delta from previous
  • Salary difference
  • Incremental steps
  • Analytical math on LAG