如何获得第二高薪的所有员工记录基础

时间:2018-02-20 08:51:01

标签: mysql database phpmyadmin

我知道如何使用

获得第二高工资表数据库表
SELECT MAX(Salary) From Employee WHERE Salary < ( SELECT Max(Salary) FROM Employee);

但我希望将薪水为第二大薪水的所有员工记录纳入表格。

4 个答案:

答案 0 :(得分:2)

Select * from employee where salary=(
SELECT MAX(Salary) From Employee WHERE Salary < ( SELECT Max(Salary) FROM Employee));

答案 1 :(得分:0)

试试这个。它应该工作。

从员工中选择*其中的工资(SELECT MAX(薪水)来自员工WHERE Salary&lt;(SELECT Max(Salary)FROM Employee));

答案 2 :(得分:0)

让所有员工的薪水等于你获得的第二高薪:

set @second_top_salary=(
SELECT MAX(salary) FROM Employee 
WHERE salary<( SELECT Max(salary) FROM employee)
);
SELECT * FROM employee WHERE salary=@second_top_salary;

DEMO

答案 3 :(得分:0)

使用LIMIT:

SELECT Salary FROM (SELECT Salary FROM Employee ORDER BY Salary DESC LIMIT 2) AS Emp ORDER BY Salary LIMIT 1