yokostan / Leetcode-Solutions

Doing exercise on Leetcode. Carry on!
0 stars 3 forks source link

Leetcode #177. Nth Highest Salary #209

Open yokostan opened 5 years ago

yokostan commented 5 years ago
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

DISTINCT takes tied numbers into consideration (100 = 100 = both 1st place), LIMIT M, x syntax means finding x numbers that follows M.