Sql 工资第二高(考虑并列)
--题目:Employee表中有ID,Name,Salary三列,求薪资排序第二高的Employee的Name
select * FROM [Employee] --等于2时为空,因为有并列第一
SELECT name from (select Name, RANK() over (order by salary desc) as rankIndex
FROM [Test].[dbo].[Employee]) as temp
where temp.rankIndex=2 -- 先找出前两高,然后找出第二高
select name from Employee where Salary=(
select top 1 salary from
(select distinct top 2 salary from Employee order by Salary desc) as temp1
order by Salary) -- 借助Max函数,先找出最大,然后在在排除最大的数据量找最大
select Name from [Employee] where Salary =(
select MAX(Salary) from [Employee] where Salary not in (select MAX(Salary) from [Employee])) --先找出前两高,然后借助min函数找出最小值,即为第二高
select Name from [Employee] where Salary =(
select min(Salary) from (select distinct top 2 salary from Employee order by Salary desc) as temp1 )
如图:
Sql 工资第二高(考虑并列)的更多相关文章
- [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- sql:找出工资第二高的人名
CREATE TABLE EmpSalaryInfo ( Id ), Name ), Salary int ) ) ) ) ) 方法1 (子查询): name from test where sala ...
- 在雇员表中查找第二高的工资SQL语句助记
"在雇员表中查找第二高的工资的员工记录"SQL语句怎么写 这个查询首先查找最高工资,然后将它从列表中排除.再查找最高工资. 非常明显,第二次返回的是 ...
- SQL Server实现 LeetCode 176 第二高的薪水
176. 第二高的薪水 SQL架构 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+- ...
- mysql 第二高薪水
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | ...
- [Leetcode] 176.第二高薪水
题目: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | ...
- Mysql训练:第二高的薪水(IFNULL,OFFSET,LIMIT)
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 ...
- [LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- LeetCode 176. 第二高的薪水(MySQL版)
0.前言 最近刷LeetCode 刷数据库题目 由于数据库课上的是SQL,而MySQL有许多自己的函数的,怕把刚学会的函数忘记 特在此记录! 1.题目 编写一个 SQL 查询,获取 Employee ...
随机推荐
- 控制面板的cpl程序列表
控制面板的cpl程序列表 学习了:https://zhidao.baidu.com/question/2141898537654796628.html 最近用来sysdm.cpl: 辅助功能选项:ac ...
- 手机APP脚本录制(LoadRunner 12)
最近因项目需要,研究了下手机APP脚本录制方法,有需要的童鞋可参考使用! 方法1: 在手机网络中设置网络代理,使用LR12选择Mobile Application – HTTP/HTML协议中代理录制 ...
- Python 第三方 http 库-Requests 学习
Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...
- (五)解决jQuery和其它库的冲突
在jQuery库中,几乎所有的插件都被限制在它的命名空间里.全局的对象都很好地存储在jQuery命名空间里,因此当把jQuery和其它javascript类库一起使用时,不会引起冲突.(注意:默认情况 ...
- hdu 1598 find the most comfortable road(并查集+枚举)
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- Chrome自带恐龙小游戏的源码研究(四)
在上一篇<Chrome自带恐龙小游戏的源码研究(三)>中实现了让游戏昼夜交替,这一篇主要研究如何绘制障碍物. 障碍物有两种:仙人掌和翼龙.仙人掌有大小两种类型,可以同时并列多个:翼龙按高. ...
- eclipse tomcat maven
jdk jre eclipse 略过 下载maven和tomcat 上apache官网下载maven:http://maven.apache.org/download.cgi. 上apache官网下载 ...
- WPF实现ScrollViewer滚动到指定控件处
在前端 UI 开发中,有时,我们会遇到这样的需求:在一个 ScrollViewer 中有很多内容,而我们需要实现在执行某个操作后能够定位到其中指定的控件处:这很像在 HTML 页面中点击一个链接后定位 ...
- linux 读取文件信息并且输出
版权为个人所有,欢迎转载如转载请说明出处.(东北大亨) http://www.cnblogs.com/northeastTycoon/p/5513231.html 以下为读取文件信息做输出操作. 1. ...
- JS基础常识理解
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...