如何在mysql中找到第二高的薪水

如何在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;