LeetCode Second Highest Salary,leetcodehighest

來源:互聯網
上載者:User

LeetCode Second Highest Salary,leetcodehighest

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 null.

感覺難在如何返回null,而且相同的薪水排在同一位。

AC代碼:

select (select distinct salary as second_highest_salary from Employee order by salary desc limit 1 offset 1)

以下:










注意那一行是null。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.