https://leetcode.com/problems/nth-highest-salary/description/

Write a SQL query to get the nth highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+

For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.

+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+

 Create table If Not Exists Employee (Id int, Salary int);
Truncate table Employee;
insert into Employee (Id, Salary) values ('', '');
insert into Employee (Id, Salary) values ('', '');
insert into Employee (Id, Salary) values ('', ''); CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M = N - 1;
RETURN (
# Write your MySQL query statement below.
SELECT
(SELECT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT M, 1) AS getNthHighestSalary
);
END
 

LeetCode 177. Nth Highest Salary的更多相关文章

  1. 【SQL】177. Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  2. leetcode - database - 177. Nth Highest Salary (Oracle)

    题目链接:https://leetcode.com/problems/nth-highest-salary/description/ 题意:查询出表中工资第N高的值 思路: 1.先按照工资从高到低排序 ...

  3. 177. Nth Highest Salary

    问题描述 解决方案 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare number int; set numbe ...

  4. [LeetCode] Nth Highest Salary 第N高薪水

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  5. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  6. LeetCode——Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  7. find the Nth highest salary(寻找第N高薪水)

    Suppose that you are given the following simple database table called Employee that has 2 columns na ...

  8. [SQL]LeetCode177. 第N高的薪水 | Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  9. LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1

    https://leetcode.com/problems/second-highest-salary/ Write a SQL query to get the second highest sal ...

随机推荐

  1. luogu p1101 单词方阵

    https://www.luogu.org/problem/show?pid=1101 很恶心的代码  就是八个方向都搜索 #include<bits/stdc++.h> using na ...

  2. 广播地址设为自己的ip地址,子网掩码设为255.255.255.255 是什么意思

    最近看<构建高性能web站点>(老版)第12章讲LVS-DR的配置,有一段针对Real Server的配置不明所以: ifconfig lo:0 125.12.12.77 broadcas ...

  3. BZOJ 2806 【CTSC2012】 Cheat

    题目链接:Cheat 话说这道题很久以前某人就给我们考过,直到现在,我终于把这个坑填上了…… 这道题要我们把一个串\(S\)划分成若干块,每块长度不小于\(L_0\),使得能够在文章库中完全匹配的块的 ...

  4. 递归--练习7--noi1750全排列

    递归--练习7--noi1750全排列 一.心得 二.题目 1750:全排列 总时间限制:  1000ms 内存限制:  65536kB 描述 给定一个由不同的小写字母组成的字符串,输出这个字符串的所 ...

  5. poj3666&&bzoj1592

    题解: 和bzoj1367差不多 然后a[i]-i不用加 然后我再另一个地方加了这句话 然后poj ac,bzoj wa poj数据水啊 代码: #include<cstdio> #inc ...

  6. 看我如何快速学习.Net(高可用数据采集平台)

    最近文章:高可用数据采集平台(如何玩转3门语言php+.net+aauto).高并发数据采集的架构应用(Redis的应用) 项目文档:关键词匹配项目深入研究(二)- 分表思想的引入 吐槽:本人也是非常 ...

  7. easyui combobox 动态加载数组数据

    怕自己忘了,记录下来以后用方便 html部分 <input id="rzcode" name="businesItemId" style="wi ...

  8. mybatis----Integer = 0 刷选不出来条件原因以及sql改法

    Xml写法: POJO: 当status的值为 0时该where SQLand status = 0并未正常拼接,也就是说test内的表达式为false,从而导致查询结果错误.但是,显然该值(Inte ...

  9. 抽象工厂 C++实现

    抽象工厂(Abstract Factory) 抽象工厂是为了提供一系列相关或相互依赖对象的接口.对象创建型模式的一种. 客户Client 抽象工厂接口AbstractFactory 抽象工厂的实现类C ...

  10. js遍历json的key和value

    遍历json对象: 无规律: <script> var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i ...