How to find third or nᵗʰ maximum salary from salary table?

后端 未结 30 731
醉酒成梦
醉酒成梦 2020-11-30 16:30

How to find third or nth maximum salary from salary table(EmpID, EmpName, EmpSalary) in optimized way?

30条回答
  •  醉话见心
    2020-11-30 17:18

    MySQL tested solution, assume N = 4:

    select min(CustomerID) from (SELECT distinct CustomerID FROM Customers order by CustomerID desc LIMIT 4) as A;
    

    Another example:

    select min(country) from (SELECT distinct country FROM Customers order by country desc limit 3);
    

提交回复
热议问题