Write a SQL query to get the second highest salary from the Employee
table.
1 | +----+--------+ |
For example, given the above Employee table, the query should return 200
as the second highest salary. If there is no second highest salary, then the query should return null
.
1 | +---------------------+ |
1 LIMIT OFFSET
第一次尝试以失败告终, 原因是因为不知道怎么处理null的情况. 当表中只有1行时, SELECT只会返回empty set 而不是 NULL.
1 | # error when occur the table contains only one row. |
2 ISNULL()函数
ISNULL(A, B) 当A为NULL的时候返回B. 这样就解决了返回NULL的情况了. 注意, 为了避免并列第一, 要用DISTINCT关键字
1 | # Write your MySQL query statement below |