题目

编写一个 SQL 查询,获取 Employee表中第 n 高的薪水(Salary)。

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

例如上述 Employee 表,n = 2 时,应返回第二高的薪水 200。如果不存在第 n 高的薪水,那么查询应返回 null

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

解法

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N = N - 1;
RETURN (
SELECT DISTINCT Salary FROM Employee GROUP BY Salary
ORDER BY Salary DESC LIMIT 1 OFFSET N
);
END

摘自:

https://www.cnblogs.com/grandyang/p/5348976.html

[LeetCode] 177.第N高薪水的更多相关文章

  1. SQL Server实现 LeetCode 177 第N高的薪水

    177. 第N高的薪水 编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary). +----+--------+ | Id | Salary | +----+------ ...

  2. [LeetCode] Second Highest Salary 第二高薪水

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

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

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

  4. mysql 第二高薪水

    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | ...

  5. LeetCode:176.第二高的薪水

    题目链接:https://leetcode-cn.com/problems/second-highest-salary/ 题目 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Sal ...

  6. [Leetcode] 176.第二高薪水

    题目: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | ...

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

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

  8. mysql查询之获取第n高薪水

    获取 Employee 表中第 n 高的薪水(Salary) +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 ...

  9. LeetCode 177 Nth-Highest Salary mysql,取第n条数据,limit子句 难度:1

    https://leetcode.com/problems/nth-highest-salary/ ATTENTION:limit 子句只能接受int常量,不能接受运算式 CREATE FUNCTIO ...

随机推荐

  1. hibernate.hbm.xml配置文件解析

    转自:https://www.cnblogs.com/uoar/p/6670612.html 1. <!DOCTYPE hibernate-mapping PUBLIC "-//Hib ...

  2. ASE Alpha Sprint - backend scrum 5

    本次scrum于2019.11.10再sky garden进行,持续30分钟. 参与人: Zhikai Chen, Jia Ning, Jiyan He 请假: Xin Kang, Lihao Ran ...

  3. 《图解HTTP》阅读总结

    前言:<图解HTTP>是一本图文并茂的好书,讲解地很详尽.目前我只完整地读了一遍,很多地方知其然不知其所以然,接下来打算抽空再读一次.这篇博文只是做个粗略记录,第二遍读完会再来编辑细化. ...

  4. Python中queue消息队列模块

    from queue import Queue from queue import PriorityQueue print("Queue类实现了一个基本的先进先出(FIFO)容器,使用put ...

  5. 消灭 Java 代码的“坏味道”

    消灭 Java 代码的“坏味道” 原创: 王超 阿里巴巴中间件 昨天 导读 明代王阳明先生在<传习录>谈为学之道时说: 私欲日生,如地上尘,一日不扫,便又有一层.着实用功,便见道无终穷,愈 ...

  6. vue2.0  之 directive指令 (自定义)

    指令 一.定义: 指令只一种可以附加到DOM元素的微命令(tiny commands). 它们通常以"v-"作为前缀, 以方便Vue知道你在使用一种特殊的标记, 从而确保语法的一致 ...

  7. php内置函数分析之strrev()

    PHP_FUNCTION(strrev) { zend_string *str; char *e, *p; zend_string *n; if (zend_parse_parameters(ZEND ...

  8. jmeter性能工具 使用手册(一)

    前置条件: 在jmeter官网下载jmter 安装包 电脑有java 环境 使用步骤: 打开jmeter 2.新建线程 Test plan--->add-->theads(users)-- ...

  9. [CF959C]Mahmoud and Ehab and the wrong algorithm

    解法 很简单对于n<=5举不出反例 如果n>5的话2,3,4好点连1,其他点连2 对于正面例子 直接所有点连1号点 其实就是结论题 代码: #include <cstdio> ...

  10. Android多线程方案

    为主线程减轻负的多线程方案有哪些呢?这些方案分别适合在什么场景下使用? Android系统为我们提供了若干组工具类来帮助解决这个问题. AsyncTask: 为UI线程与工作线程之间进行快速的切换提供 ...