DataBase -- Second Highest Salary
Question:
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 second highest salary is 200. If there is no second highest salary, then the query should return null.
Analysis:
写一个SQL语句找出Employee表中第二高的年薪,如果没有,则返回null。
我们可以先取出最大的Salary,然后再取出比最大的Salary小的最大Salary。
Answer:
select max(Salary) from Employee
where Salary < (select max(Salary) from Employee);
DataBase -- Second Highest Salary的更多相关文章
- find the Nth highest salary(寻找第N高薪水)
Suppose that you are given the following simple database table called Employee that has 2 columns na ...
- [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 ...
- [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
随机推荐
- python的元组数据类型及常用操作
Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 如下实例: tup1 = ('physi ...
- c#学习笔记《1》——regex类
C#regex是正则表达式类用于string的处理,查找匹配的字符串.1,先看一个例子Regex regex=new Regex(@”OK“)://我们要在目标字符串中找到"OK" ...
- STM32CubeMx配置USART注意的一个问题
HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, Number);意思是接收到Number个字节后,触发HAL_UART_RxCpltCal ...
- python 使用生成器 来完成 监听文件输入的例子
def tail(filename):#函数 f = open(filename,encoding='utf-8') while True: line = f.readline() if line.s ...
- maven中settings文件的配置
鉴于上一个博客写的maven打包,读者老爷们可能找不到settings文件的配置,这里专门附上settings文件的配置: 有的settings文件只含有一些空标签,需要手动去配置. <?xml ...
- 【转】让Moodle支持多个域名
默认情况下,moodle仅能绑定一个域名.但是由于学校网络分内网和外网,总希望如果是外网访问的,用外网的域名,用内网访问的,就转到内网的ip.这样访问的速度会更快一些,也减低对防火墙的压力.尤其是当外 ...
- 暗影精灵3安装无线网卡驱动(ubuntu16.04)
干货,无线网卡安装步骤: 1. 由于暗影精灵3的无线网卡较新,版本为Realtek Device b822,(查看命令为lspci | grep -i net,Ethernet controller代 ...
- JVM运行内存分配和回收
本文来自网易云社区 作者:吕宗胜 Java语言与C语言相比,最大的特点是编程人员无需过多的关心Java的内存分配和回收,因为所有这一切,Java的虚拟机都帮我们实现了.JVM的内存管理,大大降低了开发 ...
- ios下 active 演示激活
document.body.addEventListener('touchstart', function () { });
- 用jsp实现省市区三级联动下拉
jsp+jquery实现省市区三级联动下拉 不少系统都需要实现省市区三级联动下拉,像人口信息管理.电子商务网站.会员管理等,都需要填写地址相关信息.而用ajax实现的无刷新省市区三级联动下拉则可以改善 ...