如何在MYSQL中找到员工表中第二高的薪水? [英] How to find the 2nd highest salary from an employee table in MYSQL?

查看:104
本文介绍了如何在MYSQL中找到员工表中第二高的薪水?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从很多网站尝试了很多MYSQL查询,但是我无法得到我所需的结果。任何人都可以帮我解决这个问题吗?

解决方案

你可以尝试

  SELECT  *  FROM  table_name  ORDER   BY  desired_column  DESC  LIMIT  2 ; 



此查询将返回2行,其中第二行是您想要的行。

(我使用SELECT *,因为我对你的表格结构一无所知)



我希望这会有所帮助。


请阅读官方文档 [ ^ ]。



最简单的查询可能是:

  SELECT  * 
FROM EMPLOYEES e
< span class =code-keyword> ORDER BY e.SALARY DESC
LIMIT 1 1 ;


< blockquote>试试这样的事情

  SELECT  *  FROM  
SELECT *
FROM Workers
ORDER BY salary DESC
LIMIT < span class =code-digit> 2 )别名
ORDER BY 工资
LIMIT 1





我没有mysql在手边尝试,所以我希望它有效

I have tried so many MYSQL queries from many sites, but i cant get my required result.Can anyone please help me out on this issue?

解决方案

You can try

SELECT * FROM table_name ORDER BY desired_column DESC LIMIT 2;


This query will give you 2 rows in return where the second row is the one you want.
(I use SELECT * as I know nothing about your table structure)

I hope this helps.


So read the official documentation[^].

The simplest query would probably be:

SELECT  *
FROM    EMPLOYEES e
ORDER BY e.SALARY DESC
LIMIT 1,1;


Try something like this

SELECT * FROM
(SELECT *
FROM Workers
ORDER BY salary DESC
LIMIT 2) alias
ORDER BY salary
LIMIT 1



I've got no mysql at hand to try it, so i hope it works


这篇关于如何在MYSQL中找到员工表中第二高的薪水?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆