LeetCode 176 第二高的薪水

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jsszwc/article/details/88075513

题目:

https://leetcode-cn.com/problems/second-highest-salary/

题意:

在这里插入图片描述

思路:

用order by对薪水降序排序,用limit 1, 1拉出第二条,用IFNULL函数判断是否有第二条数据,没有输出NULL

代码:

# Write your MySQL query statement below
SELECT IFNULL(
    (
        SELECT DISTINCT Salary
        FROM Employee
        ORDER BY Salary DESC
        LIMIT 1, 1
    ), NULL
) AS SecondHighestSalary

猜你喜欢

转载自blog.csdn.net/jsszwc/article/details/88075513