查询mysql中第二大的记录

版权声明:如有不同见解、欢迎批评和指正 https://blog.csdn.net/I_peter/article/details/52280901
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);
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页