select Salary as SecondHighestSalary
from(select distinct Salary from Employee order by Salary desc) as tb1
i can't handle the null situation,some one help?
SELECT IF(COUNT(Salary) >= 1, Salary, NULL) AS SecondHighestSalary FROM (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 , 1) tmp
Your answer return 0 row if no second highest found, but null is required. So just add another query to handle this.
Sorry for asking you a stupid question, but why it's count>=1 instead of count>1?
The subquery will return the second highest salary and only return 1 row, so COUNT(Salary) will never > 1.
If no row from subquery, this main SELECT should return NULL as final result.
If you can read Chinese, you can have a look at my blog for other solutions. http://tsuinte.ru/2015/04/05/leetcode-database-176-second-highest-salary/
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.