Compare Employee Salaries Using LAG Function
Find employees whose salary is greater than the previous employee's salary.
sql
SELECT id, name, salary FROM ( SELECT id, name, salary, LAG(salary) OVER (ORDER BY id) AS prev_salary FROM employees ) AS salary_comparison WHERE salary > prev_salary;
This query uses the LAG() window function to compare each employee's salary with the salary of the preceding record based on the id column, returning only those whose salary is greater.
PromptDB can make mistakes. Please double-check responses.