Calculate Maximum Salary Increase Between Employees

Find the highest salary increase between consecutive employees.

sql

SELECT MAX(salary - prev_salary) AS max_increase FROM ( SELECT salary, LAG(salary) OVER (ORDER BY id) AS prev_salary FROM employees ) AS salary_diffs;

This query uses the LAG() window function to access the salary of the preceding employee based on their id, calculates the difference between the current and previous salary, and returns the maximum value found.

PromptDB can make mistakes. Please double-check responses.