找第二大的数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为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...
随机推荐
- pandas缺失值处理
1.检查缺失值 为了更容易地检测缺失值(以及跨越不同的数组dtype),Pandas提供了isnull()和notnull()函数,它们也是Series和DataFrame对象的方法 - 示例1 im ...
- Delphi2007精简版加载Borland.Studio.Together.dll错误解决办法
安装Delphi2007精简版,启动提示Borland.Studio.Together.dll加载错误,错误信息如下: Failed to load IDE add in 'C:\Program Fi ...
- BZOJ3626 LNOI2014LCA(树链剖分+主席树)
开店简化版. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- android-support-v4.jar 免积分下载
资源名称:android扩展插件 android-support-v4.jar 资源大小:137KB 上传日期:2012-10-08 资源积分:1 下载次数:136 电信下载地址:http://www ...
- py3+requests+re+urllib,爬取并下载不得姐视频
实现原理及思路请参考我的另外几篇爬虫实践博客 py3+urllib+bs4+反爬,20+行代码教你爬取豆瓣妹子图:http://www.cnblogs.com/UncleYong/p/6892688. ...
- TextView 借助Linkify,使用自定义模式设置链接
http://my.oschina.net/fengheju/blog/176105 TextView是android中的一个比较常用的控件,它有一个非常有趣的特性,可以通过android:autoL ...
- pthread_cond_wait() 函数的使用
1. 首先pthread_cond_wait 的定义是这样的 The pthread_cond_wait() and pthread_cond_timedwait() functions are us ...
- 分享一个自己做的SpringMVC的PPT
分享一个自己做的SpringMVC的PPT,由于比较忙只写了一些重要的部分
- NHibernate使用简单示例
NHibernate使用小示例 1.新建Model类库项目. 使用代码生成器生成Model类. 此处以简单的UserInfo表作为示例. 注意字段前必须以 virtual 修饰. namespace ...
- MATLAB:图形加法运算(imadd函数)
close all; %关闭当前所有图形窗口,清空工作空间变量,清除工作空间所有变量 clear all; clc; I=imread('rice.png'); %读入图像rice,赋值给I J=im ...