LeetCode Nth Highest Salary
来源:互联网 发布:热玛吉效果怎么样知乎 编辑:程序博客网 时间:2024/06/05 02:29
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
.
注意相同的salary算一位,而且limit以及offset不能用表达式,至少我写的时候是不行的。
一开始不知道如何声明一个变量,结果硬是写了这个方法:
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGIN RETURN ( select(select a.salary from(select distinct b.salary from Employee b union all select max(c.salary) from Employee c)a order by a.salary desc limit 1 offset N) );END后来在discuss看到了如何声明变量:
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGINdeclare M int;set M = N - 1; RETURN ( select distinct salary from Employee order by salary desc limit 1 offset M );END
0 0
- LeetCode Nth Highest Salary
- 【LeetCode】Second Highest Salary && Nth Highest Salary
- LeetCode | Second Highest Salary & Nth highest salary
- leetcode 177 Nth Highest Salary
- leetcode 177. Nth Highest Salary
- leetcode.177. Nth Highest Salary
- leetcode 177. Nth Highest Salary
- Leetcode 177. Nth Highest Salary
- [LeetCode]Nth Highest Salary,解题报告
- leetcode-database-177. Nth Highest Salary
- leetcode SQL题目 177. Nth Highest Salary
- 【leetcode Database】177. Nth Highest Salary
- Nth Highest Salary
- Nth Highest Salary
- 177 - Nth Highest Salary
- Nth Highest Salary
- Nth Highest Salary
- MySQL-Nth Highest Salary
- Spring MVC
- 注册表被修改的常见问题
- 第八周程序设计课解题报告
- struts2 package 属性说明
- sdut2408 Pick apples
- LeetCode Nth Highest Salary
- 第八周的药之程序风格
- ZOJ 3866 Cylinder Candy
- HDU 4089 Activation 概率dp
- Hibernate之CRUD工具类
- C++中一种十分有用的容器vector
- 第九周期末(中)考试解题报告
- 二分查找之k小数
- LaTex 设置字体颜色