📜  mysql 获得第 n 高 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:14.159000             🧑  作者: Mango

代码示例1
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  SET N = N-1;
  
  RETURN (
      # Where Salary is your column name and Employee your table
      SELECT DISTINCT(Salary) FROM Employee ORDER BY Salary DESC LIMIT N, 1
  );
END