Nth Highest Salary
来源:互联网 发布:重低音增强软件 编辑:程序博客网 时间:2024/06/05 00:30
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
.
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGIN declare M int; set M=N-1; RETURN ( # Write your MySQL query statement below. #select distinct salary from Employee order by salary desc limit n,1 SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1 );END
和Second Highest Salary思路一样,但是在这里考察函数的编写。
注意:
函数里,不能定义n这样的变量,其次在select语句里不能使用limit N-1,1这样的语句
0 0
- LeetCode Nth Highest Salary
- Nth Highest Salary
- Nth Highest Salary
- 177 - Nth Highest Salary
- Nth Highest Salary
- Nth Highest Salary
- MySQL-Nth Highest Salary
- 177. Nth Highest Salary
- Leetcode177. Nth Highest Salary
- 【LeetCode】Second Highest Salary && Nth Highest Salary
- LeetCode | Second Highest Salary & Nth highest salary
- leetcode 177 Nth Highest Salary
- LeetCode_OJ【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,解题报告
- Entity Framework 质量博客链接
- 需要的拿去—Android手表和手机通讯研究
- java学习笔记之StringBuffer(一)
- UVALive 5070 Awkward Lights
- 画线的基本方法
- Nth Highest Salary
- Java创建线程安全的方法
- 杭电 1003
- MySQL慢查询整理
- weblogic生产模式,实现启动主控时不需要输入密码
- Found 4 versions of android-support-v4.jar in the dependency list.
- ArcEngine中使用IMap.FeatureSelection获取被选中的要素
- 基站选址
- Struts 2中实现文件下载(修正中文问题)