LeetCode177——第N高的薪水

版权声明:我的GitHub:https://github.com/617076674。真诚求星! https://blog.csdn.net/qq_41231926/article/details/86517834

我的LeetCode代码仓:https://github.com/617076674/LeetCode

原题链接:https://leetcode-cn.com/problems/nth-highest-salary/description/

题目描述:

知识点:LIMIT语句、SQL函数变量的定义和使用

思路:和LeetCode176——第二高的薪水相同的解法

由于要查的是第N高的薪水,我们需要定义一个变量M,其值为N - 1。因为如果在LIMIT语句里直接写N - 1会报语法错误。

SQL语句:

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解题报告: 

猜你喜欢

转载自blog.csdn.net/qq_41231926/article/details/86517834