[MySQL] OFFSET by N-1
The general solution which should be working for all SQL (574ms, 35.61%): \n\n\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  RETURN (\n    #
The general solution which should be working for all SQL (574ms, 35.61%): \n\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  RETURN (\n    # Write your MySQL query statement below.\n    SELECT DISTINCT Salary\n    FROM Employee e1\n    WHERE N-1 = (SELECT COUNT(DISTINCT Salary) FROM Employee e2 WHERE e1.Salary < e2.Salary)\n  );\nEND\n```\n\nUsing `OFFSET` in MySQL (182ms, 99.01%): \n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\nDECLARE M INT; \nSET M=N-1;\n  RETURN (\n    # Write your MySQL query statement below.\n    SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET M\n  );\nEND\n```\n\nComment: Per MySQL documentation, `OFFSET` can only take numeric contants, i.e. not `N-1`.
['MySQL']