[LeetCode]-DataBase-Nth Highest Salary
2016-03-21 18:36
363 查看
Write a SQL query to get the nth highest salary from the
For example, given the above Employee table, the nth highest salary where n = 2 is
需求:查询第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
Employeetable.
+----+--------+ | 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
相关文章推荐
- Android官方开发文档Training系列课程中文版:构建第一款安卓应用之创建用户界面
- JAVA反射详解
- OpenCV实现基于8*8块DCT变换的图像压缩
- java 使用queue
- Activity 的四种启动模式详解
- [LeetCode]-DataBase-Department Highest Salary
- Trie树python实现
- (多线程)ProducerCustomerJDK_5
- 项目查询经验
- Android-Android studio加载9.png图片报错
- Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
- ExtJS学习-----------Ext.String,ExtJS对javascript中的String的扩展
- WPF 绑定中Converter的应用
- mac下xampp环境中yii2的migrate报错处理
- android之socket编程(二)案例
- osgi2——camel网关调用其它系统webservice
- Lazy Load, 延迟加载图片的 jQuery 插件
- 战斗力公式的推演
- [LeetCode]-DataBase-Delete Duplicate Emails
- 支付宝即时到帐接口的python实现,示例采用django框架