如何在mysql中找到第二高的薪水 [英] How to find second highest salary in mysql

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

问题描述

如何在mysql中找到第二高的薪水.所有记录均排在第二高的工资中.

How to find second highest salary in mysql. All record find in second highest salary.

Table : Employee
ID    salary      emp_name
1     400         A
2     800         B
3     300         C
4     400         D
4     400         C

*** Mysql Query: ***
SELECT * FROM employee ORDER by salary DESC LIMIT 1,2

这返回了两条记录.我不知道第二高薪水有多少条记录.

This return two record.I do not know how many record in second highest salary.

推荐答案

SELECT sal
FROM emp
ORDER BY sal DESC
LIMIT 1, 1;

你只会得到第二个最高工资.

You will get only the second max salary.

如果您需要任何第 3 个或第 4 个或第 N 个值,您可以增加第一个值,然后是 LIMIT (n-1) 即.第四薪:LIMIT 3, 1;

And if you need any 3rd or 4th or Nth value you can increase the first value followed by LIMIT (n-1) ie. for 4th salary: LIMIT 3, 1;

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

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