Saturday, 10 March 2018

Get 10th/nth Max salary of employee in SQL Server

Example:

create table #tempEmp(empid int identity(1,1),Salary money)

insert into #tempEmp
select 500
union
select 550
union
select 1000
union
select 1500
union
select 2000
union
select 2500
union
select 3000
union
select 3500
union
select 4000
union
select 4500

Here the Query to get 10th/nth Max salary of  Employee

select * from(
select row_number() over (order by salary) as sal_level,Salary from #tempEmp) A
where A.sal_level=10





2.Second way to get the same

select max(sal) from #temp where sal in(select top 10 sal from #temp order by sal desc)

No comments:

Post a Comment