Salary Gap to the Next Higher Earner
Within each department return every employee's name and the salary difference to the next higher-paid colleague in the same department (NULL for the top earner). Order by department_id, then salary descending.
Table schema
Employees(id INT PRIMARY KEY, name VARCHAR(50), department_id INT, salary INT)Sample data
id | name | department_id | salary
1 | A | 1 | 300
2 | B | 1 | 200
3 | C | 1 | 100
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.