Salary Change vs Previous Hire
Medium
LEAD & LAG Scenarios
Employees are ordered by hire date. Return each employee and the difference between their salary and the salary of the employee hired just before them (NULL for the first). Order by hire date.
Table schema
Employees(id INT PRIMARY KEY, name VARCHAR(10), hire_date DATE, salary INT)Sample data
id | name | hire_date | salary
1 | Ann | 2020-01-01 | 50
2 | Bob | 2021-06-01 | 60
3 | Cy | 2022-03-01 | 55
4 | Dee | 2023-09-01 | 70
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.