0
点赞
收藏
分享

微信扫一扫

leetcode刷题MySQL题解十五


leetcode刷题MySQL题解十五

题目叙述

Employee 表:
±------------±-----+
| Column Name | Type |
±------------±-----+
| id | int |
| salary | int |
±------------±-----+
id 是这个表的主键。
表的每一行包含员工的工资信息。

编写一个 SQL 查询,获取并返回 Employee 表中第二高的薪水 。如果不存在第二高的薪水,查询应该返回 null 。

查询结果如下例所示。

示例 1:

输入:
Employee 表:
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
±—±-------+
输出:
±--------------------+
| SecondHighestSalary |
±--------------------+
| 200 |
±--------------------+
示例 2:

输入:
Employee 表:
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
±—±-------+
输出:
±--------------------+
| SecondHighestSalary |
±--------------------+
| null |
±--------------------+

题目解答

# Write your MySQL query statement below
select max(Salary) as SecondHighestSalary from Employee where Salary NOT IN (select max(Salary) from Employee);

题目运行

leetcode刷题MySQL题解十五_数据库


举报

相关推荐

0 条评论