找第二大的数SQL-Second Highest Salary

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的更多相关文章
- c# 各种排序算法+找第二大的数+句子单词反转
冒泡排序 // 冒泡排序 bubble sort public static int[] BubbleSort(int []array) { bool isContinue = true; ; i & ...
- 如何使用一次for循环得到数组中第二大的数和第三大的数
装载声明:http://blog.csdn.net/lxsmk9059/article/details/77920206?locationNum=1&fps=1 ,,,,,,,,}; ]; ] ...
- LeetCode SQL: Second Highest Salary
, NULL, salary) as `salary` from ( ,) tmp Write a SQL query to get the second highest salary from th ...
- python找出数组中第二大的数
#!usr/bin/env python #encoding:utf-8 ''''' __Author__:沂水寒城 功能:找出数组中第2大的数字 ''' def find_Second_large_ ...
- sql求倒数第二大的数,效率不高,但写法新颖
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Microsoft的考验――查找第二大的数
#include<stdio.h> int main() { int n,m,t,max,max1; scanf("%d",&n); while(n--) { ...
- [LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- [leetcode]Second Highest Salary
找第二大 # Write your MySQL query statement below SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN ( ...
- 算法题之找出数组里第K大的数
问题:找出一个数组里面前K个最大数. 解法一(直接解法): 对数组用快速排序,然后直接挑出第k大的数.这种方法的时间复杂度是O(Nlog(N)).N为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...
随机推荐
- Linux下DB2命令学习及整理
DB2相关数据库命令 1.数据库实例的启动首先要启动数据库的实例,即切换到db2inst1用户(注:db2inst1用户为当前数据库的实例),然后执行db2start启动数据库的实例 [root@lo ...
- 《ERP系统》客户信用及风控代码
1.风控核心代码: <?php namespace core\models; class SalesCustomersFacade extends \common\models\Base{ /* ...
- 【转】Thread Local的正确原理与适用场景
本文转发自技术世界,原文链接 http://www.jasongj.com/java/threadlocal/ ThreadLocal解决什么问题 由于 ThreadLocal 支持范型,如 Thre ...
- BZOJ3876 AHOI/JSOI2014支线剧情(上下界网络流)
原图所有边下界设为1上界设为inf花费为时间,那么显然就是一个上下界最小费用流了.做法与可行流类似. 因为每次选的都是最短路增广,且显然不会有负权增广路,所以所求出来的可行流的费用就是最小的. #in ...
- xml和对象 转换
//测试数据 static List<User> list = new List<User>() { new User(){id=1001 ,name="语文&quo ...
- luogu4849 寻找宝藏 (cdq分治+dp)
设f[i]是已经走到i号点的值. 先要给第四维离散化.然后去重 第一维排序,第二维cdq分治,第三维cdq分治,第四维树状数组,找到满足j(x,y,z,w)<=i(x,y,z,w)的j,给i统计 ...
- mysql数据库几种引擎
· InnoDB:用于事务处理应用程序,具有众多特性,包括ACID事务支持.(提供行级锁) · BDB:可替代InnoDB的事务引擎,支持COMMIT.ROLLBACK和其他事务特性. · Memor ...
- ASP.NET服务器端控件原理分析
服务器端控件触发事件分两种: 1.服务器端控件Button被渲染成客户端的 <input type="submit" name="Button1" val ...
- A1103. Integer Factorization
The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...
- Java:返回当前内存信息
今天有个小程序想获得当前系统可用的内存信息,到百度搜索了一下,看到很多人都在说要采用JNI来做,JAVA本身没办法实现,经过半个多小时的搜索,终于找到了,原来Java本身已经有这个功能了.唉,看来是很 ...