Query to find nth highest salary of a Employee?

Kirthiga
Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 1414
create table Employee(Name varchar,Salary money)
insert into Employee values ('A',1000),('B',2000),('C',2000),('D',3000),('E',4000),('F',5000)
select * from Employee

--First highest salary
;with highest as (
select *,DENSE_RANK() over(order by salary desc)high from Employee
)select Name from highest where high=1

--Fourth highest salary
;with highest as (
select *,DENSE_RANK() over(order by salary desc)high from Employee
)select Name,Salary from highest where high=4

Comments or Responses

Login to post response