/sql

This is a repo of containing Leetcode SQL questions and solutions.

Question

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN DECLARE result INT; SET result = NULL; SET N = N - 1; SELECT DISTINCT salary INTO result FROM Employee ORDER BY salary DESC LIMIT 1 OFFSET N; RETURN ( result ); END

Link SELECT DISTINCT( SELECT DISTINCT salary FROM Employee e ORDER BY salary DESC LIMIT 1 OFFSET 1 ) AS SecondHighestSalary;