查詢mysql中第二大的記錄
阿新 • • 發佈:2019-02-08
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);
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查詢前兩條記錄的方法: