SQL Practice Logo

SQLPractice Online

Scenario SQL Question

Compare to Previous & Next Hire (LAG / LEAD)

Build mastery in Ctes Window with this scenario-based SQL challenge and live execution support.

Problem Statement

For each employee, ordered by hire_date within their department, show the previous and next hired employee's salary, plus the salary change vs the previous hire. Return department_name, first_name, last_name, hire_date, salary, prev_emp_salary, next_emp_salary, salary_change — ordered by department_name, hire_date, employee_id.

Relevant Tables

employeesdepartments

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: