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. ARIMA模型识别、计算p、q值

    #-*- coding: utf-8 -*- #确定最佳p.d.q值 import pandas as pd #参数初始化 discfile = '../data/discdata_processed ...

  2. (二) 关于配置travis-ci持续集成python pytest测试的相关记录

    接上篇 上篇只是非常官方的描述了一下travis-ci是包括了些什么部分会如何工作但是并没有深入介绍也没有写demo. 这里先贴上一个我已经测试好了的python_travis-ci的环境 https ...

  3. MidoNet 安装(Kilo RDO)(最老版)

    一.初始化(Kilo RDO)版(最老版) 环境介绍 系统 CentOS 7.3 主机ip 10.211.55.5 主机名 midonet 1.配置yum源 ###OpenStack源 yum ins ...

  4. BZOJ4832[Lydsy1704月赛]抵制克苏恩——期望DP

    题目描述 小Q同学现在沉迷炉石传说不能自拔.他发现一张名为克苏恩的牌很不公平.如果你不玩炉石传说,不必担心,小Q 同学会告诉你所有相关的细节.炉石传说是这样的一个游戏,每个玩家拥有一个 30 点血量的 ...

  5. Educational Codeforces Round 58 Div. 2 自闭记

    明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...

  6. Harmonic Number LightOJ - 1234 (分段打表)

    题意: 求调和级数,但n很大啦.. 解析: 分段打表  每间隔50存储一个数,在计算时  只需要找到离输入的n最近的那个数 以它为起点 开始计算即可 emm...补充一下调和级数的运算公式   r为常 ...

  7. day28 property 装饰器

    方法属性装饰器 本质上来说就是将方法的执行括号去掉,这样将一个方法掩饰成了一个变量名字,变成了类似属性的东西内置装饰器函数,只在面向对象中使用 from math import pi class Cr ...

  8. MT【206】证明整数数列

    已知方程$x^3-x^2-x+1=0$,的三根根为$a,b,c$,若$k_n=\dfrac{a^n-b^n}{a-b}+\dfrac{b^n-c^n}{b-c}+\dfrac{c^n-a^n}{c-a ...

  9. 【Luogu4630】【APIO2018】 Duathlon 铁人两项 (圆方树)

    Description ​ 给你一张\(~n~\)个点\(~m~\)条边的无向图,求有多少个三元组\(~(x, ~y, ~z)~\)满足存在一条从\(~x~\)到\(~z~\)并且经过\(~y~\)的 ...

  10. android-support-v4.jar 免积分下载

    资源名称:android扩展插件 android-support-v4.jar 资源大小:137KB 上传日期:2012-10-08 资源积分:1 下载次数:136 电信下载地址:http://www ...