please, why I am wrong, how can I use subquery to return null?


  • 0
    A

    SELECT e1.Salary as SecondHighestSalary FROM Employee e1
    WHERE 1 = (SELECT COUNT(DISTINCT e2.Salary) FROM Employee as e2 where e2.Salary > e1.Salary);


  • 0
    A

    Also , I tried this way , not work neither.

    SELECT (CASE WHEN e1.Salary THEN e1.Salary else NULL END) as SecondHighestSalary FROM Employee e1
    WHERE 1 = (SELECT COUNT(DISTINCT e2.Salary) FROM Employee as e2 where e2.Salary > e1.Salary);


Log in to reply
 

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