[LeetCode][SQL]Nth Highest Salary
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
.
https://leetcode.com/problems/nth-highest-salary/
题目是不难的,就是谁能告诉我为什么我本地的MySQL无论如何都是错的。
加上delimiter $$也并没有什么用...
还有第7行为毛不能加分号或者$$...
1 #drop function getNthHighestSalary$$ 2 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT 3 BEGIN 4 DECLARE M INT; 5 SET M = N - 1; 6 RETURN ( 7 select distinct Salary from Employee order by Salary desc limit M, 1 8 ); 9 END
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步