My solution for any number highest salary


  • 0
    2

    SELECT IF((SELECT COUNT(DISTINCT(Salary)) FROM Employee) < 2, null, ordered_table.Salary) AS 'SecondHighestSalary' FROM (SELECT DISTINCT(Salary) AS Salary FROM Employee ORDER BY Salary DESC LIMIT 2) AS ordered_table ORDER BY ordered_table.Salary ASC LIMIT 1;

    change both 2 to any number you want.


Log in to reply
 

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