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.

需求:查询第N高的工资

CREATE TABLE Employee(
Id TINYINT UNSIGNED,
Salary DECIMAL(10,2)
)ENGINE=MyISAM CHARSET=utf8;

-- sql 使用 limit 和 ORDER BY
DROP FUNCTION IF EXISTS getNthHighestSalary;
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE m INT;
SET m = n -1;
RETURN (
# Write your MySQL query statement below.
SELECT DISTINCT salary FROM employee ORDER BY salary DESC LIMIT m,1
);
END

[LeetCode]-DataBase-Nth Highest Salary的更多相关文章

  1. LeetCode 177. Nth Highest Salary

    https://leetcode.com/problems/nth-highest-salary/description/ Write a SQL query to get the nth highe ...

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

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

  3. 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. +----+ ...

  4. LeetCode——Nth Highest Salary

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

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

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

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

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

  7. 【SQL】177. Nth Highest Salary

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

  8. 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 ...

  9. Leetcode 176. Second Highest Salary

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

  10. LeetCode DB: Department Highest Salary

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

随机推荐

  1. 【golang】浅析rune数据类型

    golang中string底层是通过byte数组实现的.中文字符在unicode下占2个字节,在utf-8编码下占3个字节,而golang默认编码正好是utf-8. golang中还有一个byte数据 ...

  2. C#获取局域网主机

    C#获取局域网主机 最近在做一个使用MSRDPClient来实现远程桌面功能,需要先判断一下该局域网主机是否在线,所以就需要获取一遍局域网主机. 首先获取本地IP地址,这里需要注意的是,要排除掉虚拟机 ...

  3. ArcGis执行StartEditing(true)时,winform程序直接崩溃.

    问题描述:在Program中配置了ArcGis的许可,又在winform窗体添加了许可,导致执行StartEditing(true)时,winform程序直接崩溃. 原代码如下: static cla ...

  4. java学习笔记(4)多态

    一.多态 --------------------------------------------- 1.定义:某一类事物的多种存在形态 例如:动物中猫,狗. 猫这个对象对应的类型是猫类型 猫 x  ...

  5. Java RMI 最简单实例

    IHello.java import java.rmi.Remote; import java.rmi.RemoteException; public interface IHello extends ...

  6. [转载]排序:长度为n的数组乱序存放着0至n-1. 现在只能进行0与其他数的swap

    长度为n的数组乱序存放着0至n-1. 现在只能进行0与其他数的swap 请设计并实现排序. google笔试小题.题目来源:http://wenku.baidu.com/view/5aa818dda5 ...

  7. 第五小节之GUI(图形用户界面)

    GUi:全程是Graphical User Interface,即图形用户界面,就是应用程序提供给用户操作的图形界面,包括窗口.菜单.按钮.工具栏和其它各种图形界面元素.提供了丰富的类,这些类分别位于 ...

  8. mongoose 开源http库

    Mongoose是一个用C编写的网络库.它为客户端和服务器模式实现TCP,UDP,HTTP,WebSocket,CoAP,MQTT的事件驱动的非阻塞API. 设计理念: Mongoose有三个基本的数 ...

  9. Linux man学习

    5 man    man是manual的简写,Linux求助的工具    man  命令行,如 man  date 在我学习鸟哥私房菜的时候,也称man为man page  手册页入口:1 用户指令2 ...

  10. PAT Advanced 1033 To Fill or Not to Fill (25 分)

    With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...