LeeCode——Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the query should return 200 as the second highest salary.
If there is no second highest salary, then the query should return null.
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
此题的难点是:
- 针对可能存在的重复数值,选出唯一的数值(使用
distinct); - 选取第二个数值,则需要使用
limit,offset确定数值; - 查询的数值可能为不存在,此时就需要返回
NULL(使用IFNULL).
答题如下所示:
# Write your MySQL query statement below
select
ifnull(
(select distinct Salary from Employee order by Salary desc limit 1,1),
NULL
)
as SecondHighestSalary
PS:
如果您觉得我的文章对您有帮助,请关注我的微信公众号,谢谢!
LeeCode——Second Highest Salary的更多相关文章
- [LeetCode] Department Highest Salary 系里最高薪水
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- [LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1
https://leetcode.com/problems/second-highest-salary/ Write a SQL query to get the second highest sal ...
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- TSQL Beginners Challenge 1 - Find the second highest salary for each department
很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...
- Leetcode 176. Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- find the Nth highest salary(寻找第N高薪水)
Suppose that you are given the following simple database table called Employee that has 2 columns na ...
- [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
随机推荐
- openssl rsa加密,解密以及X509证书的使用
Openssl的相关使用 生成证书 生成证书见:使用 openssl 生成证书 代码实现 Cert.h #ifndef _CERT_H #define _CERT_H ///header files ...
- Linux命令: cat
-s 连续多个空行显示为一个空行. -n 给每一行前显示行号. -b 只给非空行前显示行号. -E 在每行后显示一个$ cat f - g 把文件f的内容.STDIN.文件g的内容连接起来 .
- C学习笔记(1)---数据类型,变量,储存类
1.常用基本数据类型占用空间(64位机器为例): char : 1个字节 -- int :4个字节 -- float:4个字节 -- double:8个字节 2.书写类型: A.整数: a. 默认为1 ...
- 第十二周Scrum会议
本次照片 总结上周所达成的工作 做到的工作 1. 将前端页面进行了比较美观的美化 2. 实现了后台的代码的整合,同时将flask项目的整体框架搭建完成 3. 进行了数据库的建表等一些工作 遇到的难点 ...
- lstm和gru详解
一.LSTM(长短期记忆网络) LSTM是一种特殊的RNN类型,一般的RNN结构如下图所示,是一种将以往学习的结果应用到当前学习的模型,但是这种一般的RNN存在着许多的弊端.举个例子,如果我们要预测“ ...
- C++ class内的 ++ 重载,左++,右++,重载示例。
#include <iostream> // overloading "operator ++ " inside class // ++ 是一元操作符 //////// ...
- 鲜贝7.3--postman安装
Postman电脑客户端安装: Postman的安装非常简单,在windows系统只需要双击安装包,然后什么都不需要操作,它直接就自己完成了,如下图.如果是mac 也是跟普通软件的安装方法相同.在初次 ...
- luoguP2480 [SDOI2010]古代猪文
题意 考虑所求即为:\(G^{\sum\limits_{d|n}C_n^d}\%999911659\). 发现系数很大,先用欧拉定理化简系数:\(G^{\sum\limits_{d|n}C_n^d\% ...
- Node.js 获取本机Mac地址
首先我们要先加载一个包用于获取mac地址 npm install getmac 加载完毕会在node_modules文件夹下发现一个getmac文件夹,我们把对应的路径加载到程序中 源码如下: var ...
- eclipse maven项目如何将所有的jar包复制到lib目录下?
1.情景展示 我们知道,maven项目的jar包并不存在于项目当中,项目所需的jar包都保存在本地仓库中,如果本地仓库没有,会从配置的中央仓库下载,如果中央仓库也没有就会报错: 如上图所示,我想将 ...
