Vadivelan's Tech Blog

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;





Posted by VP at 6:19 PM No comments:
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Search This Blog

Blog Archive

  • ►  2008 (2)
    • ►  July (2)
      • ►  Jul 08 (1)
      • ►  Jul 29 (1)
  • ►  2010 (1)
    • ►  September (1)
      • ►  Sep 15 (1)
  • ►  2012 (1)
    • ►  June (1)
      • ►  Jun 04 (1)
  • ►  2014 (2)
    • ►  September (2)
      • ►  Sep 21 (1)
      • ►  Sep 23 (1)
  • ►  2017 (4)
    • ►  March (4)
      • ►  Mar 01 (1)
      • ►  Mar 02 (1)
      • ►  Mar 17 (1)
      • ►  Mar 19 (1)
  • ▼  2022 (7)
    • ►  August (1)
      • ►  Aug 31 (1)
    • ►  September (2)
      • ►  Sep 01 (1)
      • ►  Sep 30 (1)
    • ►  October (2)
      • ►  Oct 27 (2)
    • ▼  November (2)
      • ▼  Nov 01 (2)
        • Query to find 2nd top salary in each department
        • SQL Queries Asked in Interviews
Simple theme. Powered by Blogger.