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. UVa 12034 比赛名次(递推)

    https://vjudge.net/problem/UVA-12034 题意: A.B两人赛马,最终名次有3种可能:并列第一:A第一B第二:B第一A第二.输入n,求n人赛马时最终名次的可能性的个数除 ...

  2. SQL语句主要的分类

    SQL语言的命令通常分为四类1.数据定义语言(DDL) 创建.修改或删除数据库中各种对象,包括表.视图.索引等. 命令:CREATE TABLE , CREATE VIEW, CREATE INDEX ...

  3. Kotlin中的object 与companion object的区别

    之前写了一篇Kotlin中常量和静态方法的文章,最近有人提出一个问题,在companion object中调用外部的成员变量会调用不到,这才意识到问题,本篇文章会带着这个疑问来解决问题. 一. obj ...

  4. c# 如何调用python脚本

    1.net4.5: http://www.jb51.net/article/84418.htm 2.net4.0: https://www.cnblogs.com/shiyingzheng/p/605 ...

  5. freemarker多个checkbox一个被选中示例

    前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的不难!!!!! 前端真的 ...

  6. hrbust 1621 迷宫问题II 广搜

    题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...

  7. CtaAlgo vs PyAlgoTrade

    转自知乎:https://zhuanlan.zhihu.com/p/21971854 在Python量化领域,PyAlgoTrade和zipline并列两大策略回测框架的先驱,其中PyAlgoTrad ...

  8. matlab 读多个文件夹(有名字规律)中的文件名字保存到txt中

    save_file_name='C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\OCR\result6\'; :: image_path=strcat('C:\User ...

  9. backports移植rtlwifi驱动

    /************************************************************************ * backports移植rtlwifi驱动 * 说 ...

  10. Ipv4和Ipv6的地址字符串长度

    SOURCE   IPv4采用32位地址长度      xxx.xxx.xxx.xxx  15max(string) IPv6采用128位地址长度   估计是  xxx.xxx.xxx.xxx. xx ...