当前位置:网站首页>力扣(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
边栏推荐
- @Query difficult and miscellaneous diseases
- arduino字符串转16进制数 大彩串口屏用。
- Technology is to be studied
- [defect detection] automatic defect detection of printed circuit board based on Matlab GUI [including Matlab source code 1912]
- 组件与路由
- 【缺陷检测】基于matlab GUI印刷电路板自动缺陷检测【含Matlab源码 1912期】
- 音视频与CPU架构
- R 语言降维的 PCA 与自动编码器
- Oracle连接问题以及解决方案
- PyQt theme
猜你喜欢

OpenAPI 3.0 specification - Food Guide

无法上网问题解决过程

应届毕业生谈毕业的故事

College Students' big factory road

How did the thief unlock the password after the iPhone was stolen? After reading the long knowledge

2021-08-04

OpenAPI 3.0 规范-食用指南

MySQL必須掌握4種語言!
![[image filtering] image filtering system based on Matlab GUI [including Matlab source code 1913]](/img/53/6683e7db960fbba773a9013985dcca.jpg)
[image filtering] image filtering system based on Matlab GUI [including Matlab source code 1913]

win32
随机推荐
分布式电商项目 谷粒商城 学习笔记<3>
How do I fix the iPhone green screen problem? Try these solutions
How to add a regression equation to a plot in R
Limit the input character length to 1 character in English and 2 characters in Chinese
财富自由技能:把自己产品化
df报错Stale file handle
业务流程图设计
Interviewer: please name four ways to exchange the values of two variables without using third-party variables
喜讯 | 祝贺Apache Linkis(incubating) 社区新增5位Committer
如何在 ggplot2 中向绘图中添加表格
How to solve the problem that the iPhone 13 lock screen cannot receive the wechat notification prompt?
. Net7 miniapi (special part):preview5 optimizes JWT verification (Part 2)
无法上网问题解决过程
网上股票开户安全吗?
The "more" option of Spreadtrum platform dearmcamera2 is removed
100002nd prime
我在中山,到哪里开户比较好?网上开户是否安全么?
Dynamic analysis and calculation of expression, flee is really sweet to use
Breadth first traversal of Graphs
Wechat launched a web version transmission assistant. Is it really easy to use?