Monday, 2 July 2018

SQL Query For Finding nth Heighest & Lowest Salary

SQL Query For Finding nth Heighest Salary

SELECT Salary,EmpName
FROM
  (
   SELECT Salary,EmpName,ROW_NUMBER() OVER(ORDER BY Salary Desc) As RowNum
   FROM EMPLOYEE
   ) As A
WHERE A.RowNum = 3;

SQL Query For Finding nth LowestSalary

SELECT Salary,EmpName
FROM
  (
   SELECT Salary,EmpName,ROW_NUMBER() OVER(ORDER BY Salary ASC) As RowNum
   FROM EMPLOYEE
   ) As A
WHERE A.RowNum = 2;