How to find the 2nd lowest salary in each department

SELECT 

    department_id, first_name, salary, 

    NTH_VALUE(salary, 2) OVER (PARTITION BY department_id 

ORDER BY salary 

RANGE BETWEEN UNBOUNDED PRECEDING 

AND UNBOUNDED FOLLOWING) "2nd_lowest_sal"

FROM employees

ORDER BY department_id, salary;





No comments:

Post a Comment