找第二大的数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为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...
随机推荐
- rem布局进阶
<script>!function(e){function t(a){if(i[a])return i[a].exports;var n=i[a]={exports:{},id:a,loa ...
- XE2 运行时 item not found的解决办法
.net类库的原因. 将C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG下面的 machine.config.default 改名为machin ...
- CF527D
题面 这题还挺水的,把那个式子稍微变形一下就可以的到xi-wi>=xj+wj,易知:若把每个点看做一条线段,左端点是xi-wi,右端点是xi+wi,就只要求最多的不重叠的线段数就可以了,然后就是 ...
- BZOJ3750[POI2015]Pieczęć——链表
题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色. 你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上的图案.印的过程中需要满足以下要求: ...
- Picture POJ - 1177(扫描线求面积并)
题意:求矩形并的面积.. 解析: 扫描线第一道题....自下而上扫描的... 如果不懂什么是扫描线戳我 #include <iostream> #include <cstdio> ...
- hdu 4897 Little Devil I (树链剖分+线段树)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意: 给你一棵树,一开始每条边都是白色,有三种操作: 1.将 u - v路径上的边转换颜色 ...
- 05 Zabbix triggers--action--event
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 05 Zabbix triggers--action--event 动作action: 在配置好监 ...
- cf983E NN Country (倍增+dfs序+树状数组)
首先可以求出从某点做$2^k$次车能到的最浅的点,这个只要dfs一下,把它的孩子能到的最浅的点更新过来就可以 然后倍增地往上跳,不能跳到lca的上面,记录坐车的次数ans 此时有三种情况(设最远能跳到 ...
- 【Codeforces 98E】 Help Shrek and Donkey
http://codeforces.com/problemset/problem/98/E (题目链接) 题意 A君有n张牌,B君有m张牌,桌上还有一张反扣着的牌,每张牌都不一样. 每个回合可以做两件 ...
- SpringBoot集成RocketMQ
实战,用案例来说话 前面已经说了JMS和RocketMQ一些概念和安装,下面使用SpringBoot来亲身操作一下. 生产者的操作 SpringBoot项目创建完成,引入依赖是第一步: <dep ...