美文网首页
第N高薪水

第N高薪水

作者: A_rrow | 来源:发表于2019-07-22 17:34 被阅读0次

    思路和上题一样,需要注意的是函数中写法.limit中的N-1不可以直接写,需要另外定义。另外是需要注意定义完变量后加个;

    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
        declare M int;
        set M = N -1;
      RETURN (
          select ifnull(
            (select distinct(salary) from employee order by salary desc limit M,1),NULL
          ) as getNthHighestSalary
          
      );
    END
    

    相关文章

      网友评论

          本文标题:第N高薪水

          本文链接:https://www.haomeiwen.com/subject/fonwlctx.html