SQL query to find Nth highest salary

前端 未结 9 805
清酒与你
清酒与你 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条回答
  •  温柔的废话
    2020-12-15 02:38

    Change nth highest salary value just put the value of 'N'

    SELECT e1.EmployeeName, e1.EmployeeSalary from Employee e1
    where N = (
    select COUNT(e2.EmployeeSalary) from Employee e2 where e2.EmployeeSalary >= e1.EmployeeSalary)
    

提交回复
热议问题