题目

编写一个 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. Echarts数据可视化grid直角坐标系(xAxis、yAxis)详解:

    mytextStyle={ color:"#333", //文字颜色 fontStyle:"normal", //italic斜体 oblique倾斜 font ...

  2. javascript Math取整&获取随机数

    1.方法介绍 Math.ceil(n) 上取整,大于等于n返回与它最接近的整数 Math.floor(n) 下取整,小于等于n返回与它最接近的整数 Math.round(n) 四舍五入取整 Math. ...

  3. JVM 垃圾回收(GC)机制

    目录 一.背景 二. 哪些内存需要回收? 1.引用计数算法 2 .可达性分析算法 三. 四种引用状态 1.强引用 2.软引用 3.弱引用 4.虚引用 对象死亡(被回收)前的最后一次挣扎 方法区如何判断 ...

  4. Bootstrap框架如何设置导入链接

    bootstrap文件划分: 导入规则: 方式一:可以先下载 ----https://v3.bootcss.com/ (1) 注意事项: (2) (3) 注意1:bootstrap中的js文件依赖于j ...

  5. Maven中添加Jetty服务器配置

    <project> <!--其它配置--> <build> <plugins> <plugin> <groupId>org.mo ...

  6. 编译安装github上的kafka_exporter项目

    本文介绍的kafka_exporter是prometheus监控系统中针对kafka的一款监控插件,要使用这个监控插件,kafka的版本需要满足 0.10.1.0 及以上. 项目的github地址:h ...

  7. python使用etcd

    import sys import etcd client = etcd.Client( host='127.0.0.1', port=2379, allow_reconnect=True) clie ...

  8. 一个奇怪的问题:Last_Errno: 1264 Error 'Out of range value for column 0x322E36343030

    场景环境: 1. 主从都是:Server version: 5.7.16-log MySQL Community Server (GPL) 2.操作系统:CentOS release 6.7 (Fin ...

  9. APP稳定性测试-monkey执行

    Monkey命令行可用的全部选项 *示例 : adb shell monkey -p cn.lejiayuan.alpha --pct-touch 30 --pct-motion 15 --pct-t ...

  10. Task5.NB_SVM_LDA

    参考:https://blog.csdn.net/u013710265/article/details/72780520 贝叶斯公式就一行: P(Y|X)=P(X|Y)P(Y)P(X) 而它其实是由以 ...