1: 找小于最大的最大的

select max(Salary) from Employee where Salary<(select MAX(Salary) from Employee);

2. 排序

select  Salary from Employee where Salary not in (select MAX(Salary)from Employee) order by Salary desc limit 1;

  

select (

select distinct Salary from Employee order by Salary Desc limit 1 offset 1

) as SecondHeighestSalary;

  

找第n个数:

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
set N=N-1;
RETURN ( # Write your MySQL query statement below.
select Salary from Employee order by Salary desc limit 1 offset N
);
END

  

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
set N=N-1;
RETURN ( # Write your MySQL query statement below.
select distinct Salary from Employee order by Salary desc limit 1 offset N
);
END

  不能在limit 里N-1, 因为limit里不计算

哈哈: distinct :在表中可能包含重复值,返回唯一不同的值,

找第二大的数SQL-Second Highest Salary的更多相关文章

  1. c# 各种排序算法+找第二大的数+句子单词反转

    冒泡排序 // 冒泡排序 bubble sort public static int[] BubbleSort(int []array) { bool isContinue = true; ; i & ...

  2. 如何使用一次for循环得到数组中第二大的数和第三大的数

    装载声明:http://blog.csdn.net/lxsmk9059/article/details/77920206?locationNum=1&fps=1 ,,,,,,,,}; ]; ] ...

  3. LeetCode SQL: Second Highest Salary

    , NULL, salary) as `salary` from ( ,) tmp Write a SQL query to get the second highest salary from th ...

  4. python找出数组中第二大的数

    #!usr/bin/env python #encoding:utf-8 ''''' __Author__:沂水寒城 功能:找出数组中第2大的数字 ''' def find_Second_large_ ...

  5. sql求倒数第二大的数,效率不高,但写法新颖

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Microsoft的考验――查找第二大的数

    #include<stdio.h> int main() { int n,m,t,max,max1; scanf("%d",&n); while(n--) { ...

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

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

  8. [leetcode]Second Highest Salary

    找第二大 # Write your MySQL query statement below SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN ( ...

  9. 算法题之找出数组里第K大的数

    问题:找出一个数组里面前K个最大数. 解法一(直接解法): 对数组用快速排序,然后直接挑出第k大的数.这种方法的时间复杂度是O(Nlog(N)).N为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...

随机推荐

  1. WPF将数据库和GridView绑定并更改GridView模板

    首先来看一下如何使用GridView,在前台的话代码如下:这里仅仅举出一个例子,GridView是作为子项嵌套在ListView中的,这里的数据源是通过绑定的方式来绑定到GridView中的. < ...

  2. matplotlib之scatter自动绘制散点

    # 使用matplotlib.pyplot.scatter绘制散点 import matplotlib.pyplot as plt from pylab import mpl # 设置默认字体,解决中 ...

  3. Qt ------ 覆盖eventFilter(),捕获组件事件,事件处理

    在Qt中,当一个事件发生时(例如鼠标点击或某个键盘上的按键按下),其传递顺序如图所示.从这个图可以看出,事件过滤器首先获得事件,其次才是部件的 event 函数,最后是部件的事件处理函数 事件过滤器由 ...

  4. BZOJ2159 Crash的文明世界(树形dp+斯特林数)

    根据组合意义,有nk=ΣC(n,i)*i!*S(k,i) (i=0~k),即将k个有标号球放进n个有标号盒子的方案数=在n个盒子中选i个将k个有标号球放入并且每个盒子至少有一个球. 回到本题,可以令f ...

  5. BZOJ1093 ZJOI2007最大半连通子图(缩点+dp)

    发现所谓半连通子图就是缩点后的一条链之后就是个模板题了.注意缩点后的重边.写了1h+真是没什么救了. #include<iostream> #include<cstdio> # ...

  6. Spring的编程式事务和声明式事务

    事务管理对于企业应用来说是至关重要的,当出现异常情况时,它也可以保证数据的一致性. Spring事务管理的两种方式 spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务使用Transa ...

  7. mybatis There is no getter for property named '*' in 'class java.lang.String

    1.原因 server层     xxxx.get("1234") map <if test="aaa != null and aaa.id != null and ...

  8. Django model中的 class Meta 详解

    通过一个内嵌类 "class Meta" 给你的 model 定义元数据, 类似下面这样: class Foo(models.Model): bar = models.CharFi ...

  9. centos7部署posgresql和kong总结

    之前在macos系统测试安装psql和kong,但是实际环境中,大部分是部署在linux服务器上.下面记录了在centos7上部署postgresql和kong的总结以及遇到的一些问题的解决. 查看c ...

  10. Apache Shiro 用户信息保存在session方案

    描述 在使用shiro的时候,经常会有一种需求: 把登录成功后的用户对象存放到session中,方面其他地方调用.存放到session这个步骤到底应该在哪里去做,有几个地方比较合适: 调用 Subje ...