找第二大的数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为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...
随机推荐
- Centos 7最小化安装后配置
关闭SELINUX vi /etc/sysconfig/selinux SELINUX=disabled :wq 配置网卡(最小化安装后ifconfig无法使用),该配置的前提是采用 NAT模式 vi ...
- python 从filelist.txt中拷贝文件到另一文件夹中
#! python #coding:utf-8 ##!/usr/bin/python # Filename : fileCp.py import sys import os import shutil ...
- std::binary_serach, std::upper_bound以及std::lower_bound
c++二分查找的用法 主要是 std::binary_serach, std::upper_bound以及std::lower_bound 的用法,示例如下: std::vector<int& ...
- C++拷贝构造函数与 = 重载
调用拷贝构造函数进行初始化的时候,是不会调用=重载的. // test.cpp : 定义控制台应用程序的入口点. // //#include "stdafx.h" #include ...
- BZOJ3110[Zjoi2013]K大数查询——权值线段树套线段树
题目描述 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是 ...
- BZOJ1093 ZJOI2007最大半连通子图(缩点+dp)
发现所谓半连通子图就是缩点后的一条链之后就是个模板题了.注意缩点后的重边.写了1h+真是没什么救了. #include<iostream> #include<cstdio> # ...
- Fantasy of a Summation LightOJ - 1213 (快速幂)
题意: 首先 只看第一层循环的A[0],是不是用了nk-1次 A[1]也是用了nk-1次······ 所以 第一层的sum(A[i]的和) 一共用了nk-1 所以第一层为sum * nk-1 因为又 ...
- Java8的flatMap如何处理有异常的函数
Java8的flatMap函数,作用是:如果有值,为其执行mapping函数返回Optional类型返回值,否则返回空Optional. 见到的映射函数往往都只有一句话,连大括号都不需要加的,如下: ...
- MT【234】正方形染色(二)
有$n$个正方形排成一行,今用红,白,黑三种颜色给这$n$个正方形染色,每个正方形只能染一种颜色.如果要求染这三种颜色的正方形都是偶数个,问有多少种不同的染色方法. 解答: 设有$a_n$种不同的染法 ...
- 搬进Github
学习参考 萌码 一.Github简介和基本操作 Github 上操作基本上围绕一个个项目展开.项目就是一个文件夹,在github中成为“仓库”(repository),里面放着所有的项目文件,可以是代 ...