没有子查询的第二高工资

时间:2017-07-31 03:08:39

标签: sql

$newCookies = $response->getHeader('set-cookie');

我希望在不使用子查询的情况下得到第二高的薪水50000.00?

6 个答案:

答案 0 :(得分:2)

使用limitoffset(跳过最高薪水) 在MySQL中

select * from table order by Salary desc limit 1 offset 1

在SQL server

select * from table order by Salary desc offset 1 rows fetch next 1 row only

您可以尝试使用其他数据库

http://sqlfiddle.com/#!9/15c32/1/0

答案 1 :(得分:2)

尝试以下查询,它会起作用。

select max(e1.salary) from Employee e1,Employee e2 where e1.salary<e2.salary;

答案 2 :(得分:0)

你不能只使用LIMIT 1,1(在第一行之后获取第一个结果)。我来自MySql方面,因此可能需要针对Sql Server略微调整sql。

SELECT Salary FROM table ORDER BY Salary DESC LIMIT 1,1

答案 3 :(得分:0)

SELECT DISTINCT Salary FROM TABLE 按薪酬排序DESC OFFSET 1 ROWS

FETCH NEXT 1 ROW ONLY

答案 4 :(得分:0)

添加表名和列名后测试此查询

select MAX(country) as country from users where country < ( select MAX(country) as country from users where country < (SELECT MAX(country) from users ) );

答案 5 :(得分:0)

您可以使用TOP关键字从数据库表中获取记录数。例如

SELECT TOP 1 * FROM TABLE NAME