当前位置:网站首页>力扣(LeetCode)176. 第二高的薪水(2022.06.25)
力扣(LeetCode)176. 第二高的薪水(2022.06.25)
2022-06-26 02:07:00 【ChaoYue_miku】
SQL架构:
Create table If Not Exists Employee (id int, salary int)
Truncate table Employee
insert into Employee (id, salary) values ('1', '100')
insert into Employee (id, salary) values ('2', '200')
insert into Employee (id, salary) values ('3', '300')
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 |
±--------------------+
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/second-highest-salary
方法一:使用 IFNULL 和 LIMIT 子句
MySQL提交内容:
# Write your MySQL query statement below
SELECT
IFNULL(
(SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 1),
NULL) AS SecondHighestSalary
边栏推荐
- 100002nd prime
- Camtasia 2022全新版超清录制电脑视频
- The "more" option of Spreadtrum platform dearmcamera2 is removed
- 分享一些在内网操作的远程办公经验| 社区征文
- 55 pictures make you feel a bit B-tree at one time
- 在 R 中创建非线性最小二乘检验
- Technology is to be studied
- Pie chart metamorphosis record, the liver has 3000 words, collection is to learn!
- 数据库查询语句SQL中like、%、-的区别
- Gd32 ADC acquisition voltage
猜你喜欢

@Query difficult and miscellaneous diseases

多测师拱墅肖sir_工作目录下的use websocket报错解决方案

【机器学习】基于多元时间序列对高考预测分析案例

Gd32 ADC acquisition voltage
![[机器翻译]—BLEU值的计算](/img/c3/8f98db33eb0ab5a016621d21d971e4.png)
[机器翻译]—BLEU值的计算
![[flask introduction series] flask processing request and response](/img/4b/bb5d915e83341183270d492b98f7d3.png)
[flask introduction series] flask processing request and response

数字商品DGE--数字经济的财富黑马
![[machinetranslation] - Calculation of Bleu value](/img/c3/8f98db33eb0ab5a016621d21d971e4.png)
[machinetranslation] - Calculation of Bleu value

Implement decorator pattern for servicecollection

附加:HikariCP连接池简述;(并没有深究,只是对HikariCP连接池有个基本认识)
随机推荐
Redis configuration and optimization of NoSQL
Blazor University (33) form - editcontext, fieldidentifiers
[machine learning] case study of college entrance examination prediction based on multiple time series
财富自由技能:把自己产品化
Oracle练习
程序员的八年工资变动,令网友羡慕不已:你一个月顶我一年工资
MySQL doit maîtriser 4 langues!
Bloc入门之Cubit详解
Limit the input character length to 1 character in English and 2 characters in Chinese
分布式电商项目 谷粒商城 学习笔记<3>
Multi surveyor Gongshu Xiao sir_ The solution of using websocket error reporting under working directory
网上开户选哪个证券公司?网上开户是否安全么?
golang--channal与select
One year's work
How to adjust face input size
How do I fix the iPhone green screen problem? Try these solutions
[image filtering] image filtering system based on Matlab GUI [including Matlab source code 1913]
Sloppy formula
Cox 回归模型
df报错Stale file handle