LeetCode #176第二高的薪水

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

查询第二高的数据,思路就是先找到最大值,然后在剩下的数据里找到比最大值要小的最大值。

一开始我的做法是用ifnull函数,但默认值的数据类型会改变薪水的数据类型,ifnull(Salary,null)时遇到null不输出,ifnull(Salary,'null')时遇到数值会多输出双引号,这就让我很烦恼。后来干脆把ifnull去掉试试,过了。select查询遇到null值就会输出null,唉!!!

select MAX(Salary) as SecondHighestSalary from Employee where Salary < (select MAX(Salary) from Employee);

猜你喜欢

转载自blog.csdn.net/a912952381/article/details/80732033