开发者

fetch fourth maximum record from the table field

开发者 https://www.devze.com 2022-12-25 13:06 出处:网络
Following is the command to开发者_运维技巧 fetch maximum salary form empsalary table in mysql select max(salary) from empsalary;

Following is the command to开发者_运维技巧 fetch maximum salary form empsalary table in mysql

select max(salary) from empsalary;

but I want to fetch employee who got fourth highest from the list of employee. I don't want to use trigger or function because I know there is direct command to fetch.


select * from empsalary order by salary desc limit 4


It's essentially as Col. Shrapnel has stated. Select the top 4 records as sorted by salary and then choose the last record. If it's important to do it all in SQL, you could do something like this:

select min(salary) from 
  (select salary from empsalary order by salary desc limit 4) tmp;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号