--题目: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 工资第二高(考虑并列)的更多相关文章

  1. [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  2. sql:找出工资第二高的人名

    CREATE TABLE EmpSalaryInfo ( Id ), Name ), Salary int ) ) ) ) ) 方法1 (子查询): name from test where sala ...

  3. 在雇员表中查找第二高的工资SQL语句助记

            "在雇员表中查找第二高的工资的员工记录"SQL语句怎么写         这个查询首先查找最高工资,然后将它从列表中排除.再查找最高工资. 非常明显,第二次返回的是 ...

  4. SQL Server实现 LeetCode 176 第二高的薪水

    176. 第二高的薪水 SQL架构 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+- ...

  5. mysql 第二高薪水

    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | ...

  6. [Leetcode] 176.第二高薪水

    题目: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | ...

  7. Mysql训练:第二高的薪水(IFNULL,OFFSET,LIMIT)

    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 ...

  8. [LeetCode] Second Highest Salary 第二高薪水

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  9. LeetCode 176. 第二高的薪水(MySQL版)

    0.前言 最近刷LeetCode 刷数据库题目 由于数据库课上的是SQL,而MySQL有许多自己的函数的,怕把刚学会的函数忘记 特在此记录! 1.题目 编写一个 SQL 查询,获取 Employee ...

随机推荐

  1. SqlServer 书目

    1. http://www.cnblogs.com/CareySon/archive/2013/05/04/PlanCacheInSQLServerPart2.html(运行计划缓存) 2. http ...

  2. Activity入门(一)

    生命周期         onCreate():activity进行创建,在该方法中应调用setContentView(),findViewById()以及获取要展示的数据的方法(如调用manager ...

  3. Linux下快速安装Mysql及使用

    1.安装 查看有没有安装过: yum list installed mysql* rpm -qa | grep mysql* 查看有没有安装包: yum list mysql* 安装mysql客户端: ...

  4. js 快速排序

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. hibernate oneToMany 缓存

    @OneToMany(mappedBy="carFieldType", cascade={CascadeType.ALL}, fetch = FetchType.EAGER)@Ca ...

  6. url 传中文

    if (null == keyword || keyword.equals("关键字")) keyword = ""; if(keyword.length()& ...

  7. Spring 小记

    本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 使用STS新建spr ...

  8. TextView上的文字逐渐变淡直到消失

    给TextView加个动画效果,完了在个动画加个监听,里面有个动画执行完调用的方法在方法里面把TextView设置为gone,我觉得你直接加这个动画效果之后他就会不显示了,其实他还在那占有位置呢.想不 ...

  9. Struts2学习九----------处理结果类型(input)

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2处理结果类型 - SUCCESS:Action正确的执行完成,返回相应的视图,success是name属性的默认值 - ERROR:表示 ...

  10. cenos7 修改hostname

    hostnamectl set-hostname Linuxidc 如何在CentOS 7上修改主机名 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient),和灵 ...