企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[176\. 第二高的薪水](https://leetcode-cn.com/problems/second-highest-salary/) === ![](https://box.kancloud.cn/85c480fbb8eb873e84f52cac508765e8_381x458.png) 发奋图强!!!! ### 方法一 ``` SELECT DISTINCT Salary as SecondHighestSalary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET 1 ``` salary DESC LIMIT 1 OFFSET 1 but 如果只有一条数据数据了??? ![](https://box.kancloud.cn/2e5af30000f64f55fb9c03429d495041_1008x454.png) gg ``` SELECT ( SELECT DISTINCT Salary as SecondHighestSalary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET 1 ) AS SecondHighestSalary ``` ### 方法二:使用`IFNULL`和`LIMIT`子句 ``` SELECT IFNULL( (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET 1), NULL) AS SecondHighestSalary ``` IFNULL的作用是什么?下面一个简单的sql和结果说明,如果IFNULL(a,b),a接收的值为null,则返回b,否则返回a;