Can someone please explain the reason for this syntax being working differently


  • 0
    A
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    DECLARE M INT;
    SET M=N;
      RETURN (
        **SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M-1,1**
    );
    END
    

    this query gives exception when M=0 as it becomes -1
    however when I write it like

    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
    

    Please explain the difference between the two statements


  • 0
    X

    guess you cannot do calculations within "LIMIT x,y"


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.