Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 616 Bytes

File metadata and controls

23 lines (16 loc) · 616 Bytes
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE m  int;
SET m= N-1;
  RETURN (
    SELECT distinct Salary  from  Employee order by  Salary DESC limit  m,1
      
  );
END

:不能写成"SELECT distinct Salary from Employee order by Salary DESC limit N-1,1",所以声明变量m

  • limit m,n 跳过m行后再取n行
    如 limit 2,1 跳过2行,再取一行,即选取第3行数据
  • limit m offset n 跳过n行,再选取m行,
    即等价于limit n,m
    如 limit 2 offset 1 跳过1行,再取两行,即选取第2行与第3行数据