查询数据库中第二大数据的sql语句

Second Highest Salary QuestionEditorial Solution My Submissions
Total Accepted: 22254
Total Submissions: 98888
Difficulty: Easy
Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return nul
使用order by limit查询前两条记录的方法:select salary from emloyee order by salary desc limit 2;
答案: select max(Salary) as SecondHighestSalary  from Employee where Salary<(select max(Salary) from Employee);

猜你喜欢

转载自blog.csdn.net/magicianjun/article/details/80111647