176. 第二高的薪水
一、刷题内容
原题链接
https://leetcode-cn.com/problems/second-highest-salary/
内容描述
SQL架构
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null。
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
二、解题方法
1.方法一:mysql
IFNULL函数
Distinct 去重
order by 排序
# Write your MySQL query statement below
Select
IFNULL(
(Select Distinct Salary
from Employee
order by Salary desc
Limit 1 Offset 1),
NULL) AS SecondHighestSalary
本文介绍了一种使用MySQL解决LeetCode上第二高的薪水问题的方法。通过IFNULL、Distinct及Order by等函数组合,实现了对Employee表中第二高薪水的有效检索。若不存在第二高的薪水,则返回null。

被折叠的 条评论
为什么被折叠?



