SQL query to find Nth highest salary

前端 未结 9 808
清酒与你
清酒与你 2020-12-15 01:52

I am referring to following query to find Nth highest salary of a employee.

select sal from emp t where &n = (select count(sal) from (select distinct sal         


        
9条回答
  •  萌比男神i
    2020-12-15 02:34

    select sal 
    from (
      select sal, 
             dense_rank() over (order by sal desc) as rnk
    ) t
    where rnk = 5;
    

    Replace where rnk = 5 with whatever "nth" you want.

提交回复
热议问题