【leetcode】177. 第N高的薪水

【leetcode】177. 第N高的薪水_第1张图片

这题其实和177思想比较接近,排序就行了

代码:

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  RETURN (
      # Write your MySQL query statement below.
  select Salary from (SELECT a.Salary, (SELECT count(Salary) FROM Employee WHERE Salary > a.Salary)+1 AS rank FROM Employee a ORDER BY rank) t where rank = N
  );
END

 

你可能感兴趣的:(LeetCode)