[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 ...
随机推荐
- 03: redis高级
1.1 布隆过滤器 1.布隆过滤器是什么?(判断某个key一定不存在) 1. 本质上布隆过滤器是一种数据结构,比较巧妙的概率型数据结构 2. 特点是高效地插入和查询,可以用来告诉你 “某样东西一定不存 ...
- 反向传播算法-损失函数&激活函数
在监督学习中,传统的机器学习算法优化过程是采用一个合适的损失函数度量训练样本输出损失,对损失函数进行优化求最小化的极值,相应一系列线性系数矩阵W,偏置向量b即为我们的最终结果.在DNN中,损失函数优化 ...
- Codeforces 1215E. Marbles
传送门 注意到 $a$ 的值的数量并不大,考虑状压 $dp$ 设 $f[S]$ 表示此时确定的数集合为 $S$ ,且按某种顺序从数列开头排列完成的最小交换次数 那么每个状态枚举最后一个填的数,加上代价 ...
- C++ 内联函数 inline关键字
inline 关键字主要功能是为了 代替掉 宏代码片段. 在C++中使用关键字inline关键字声明内联函数. inline int fun(int a,int b) { return a < ...
- orm的设计思路
一,我们先搞懂什么是orm? ORM:对象关系映射(Object Relational Mapping,简称ORM),目的是想像操作对象一样操作数据库.因为数据库不是面向对象的,所以需要编程进行映射. ...
- 【三】Django模版的使用
作为Web框架,Django提供了模板,可以很便利的动态生成HTML 模版系统致力于表达外观,而不是程序逻辑 模板的设计实现了业务逻辑(view)与显示内容(template)的分离,一个视图可以使用 ...
- 企业面试题|最常问的MySQL面试题集合(二)
MySQL的关联查询语句 六种关联查询 交叉连接(CROSS JOIN) 内连接(INNER JOIN) 外连接(LEFT JOIN/RIGHT JOIN) 联合查询(UNION与UNION ALL) ...
- scrapy框架设置代理ip,headers头和cookies
[设置代理ip] 根据最新的scrapy官方文档,scrapy爬虫框架的代理配置有以下两种方法: 一.使用中间件DownloaderMiddleware进行配置使用Scrapy默认方法scrapy s ...
- 【maven】IDEA:存在jar包,pom.xml文件没报错,但是Maven-Project-Dependencies有红线报错
1.这个问题很简单 把pom.xml里这些出错的jar包的引用先删除,再刷新一次,再添上,就行了 2.大概是idea有点反应迟钝
- 数据库(一):suse下MySQL安装
1.准备工作从MySQL官网上分别下载mysql服务器端于客户端包:MySQL-server-5.5.31-1.linux2.6.x86_64.rpmMySQL-client-5.5.31-1.lin ...