[LeetCode]-DataBase-Nth Highest Salary
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的更多相关文章
- LeetCode 177. Nth Highest Salary
https://leetcode.com/problems/nth-highest-salary/description/ Write a SQL query to get the nth highe ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- 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. +----+ ...
- LeetCode——Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- find the Nth highest salary(寻找第N高薪水)
Suppose that you are given the following simple database table called Employee that has 2 columns na ...
- [SQL]LeetCode177. 第N高的薪水 | Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- 【SQL】177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- 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 ...
- Leetcode 176. Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- LeetCode DB: Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
随机推荐
- linux 内核数据结构之红黑树.
转载: http://www.cnblogs.com/haippy/archive/2012/09/02/2668099.html https://zh.wikipedia.org/zh/%E7%BA ...
- VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了!
VS Code Python 全新发布!Jupyter Notebook 原生支持终于来了! 北京时间 2019 年 10 月 9 日,微软发布了全新的 VS Code Python 插件,带来了众多 ...
- c#服务端图片打包下载
一,设计多图片打包下载逻辑:1,如果是要拉取腾讯云等资源服务器的图片,2,我们先把远程图片拉取到本地的临时文件夹,3,然后压缩临时文件夹,4,压缩完删除临时文件夹,5,返回压缩完给用户,6,用户就去请 ...
- docker安装笔记
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相 ...
- 关于KMeans和range的使用
#!/usr/bin/python#-*-coding:utf-8-*-import numpy as npfrom sklearn.cluster import KMeansfrom scipy.s ...
- 修改文件夹的所有者为www
切换到root用户:su - root 修改文件所属用户和用户组:chown 用户:用户组 文件名如果用户和用户组是www,那么需要执行命令如下:chown www:www filename -R ( ...
- Celery多队列配置
Celery多队列配置 Celery官方文档 项目结构 /proj -__init__ -app.py #实例化celery对象 -celeryconfig.py #celery的配置文件 -task ...
- INSERT - 在表中创建新行
SYNOPSIS INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT ...
- fork树
i son/pa ppid pid fpid parent parent parent child child parent child parent parent child child child ...
- mysql占用磁盘IO过高的解决办法
一.现象 最近发现Mysql服务器磁盘IO一直很高 [root@push-- ~]# iostat -k -d -x Linux -.el7.x86_64 (push--) 2019年07月05日 _ ...