select ( select distinct Salary from Employee order by Salary Desc limit 1 offset 1 )as second
Change the number after 'offset' gives u n-th highest salary
the Simplest solution
WHERE Salary not in (SELECT max(Salary) FROM Employee )
I was using the middle sentence in mysql, but it failed. Why do you put another select out of the whole sentence? Thanks.
This ensures that "If there is no second highest salary, then the query should return null"
I have the same idea, but the performance seems terrible. My runtime of 1229 ms puts me dead last. I don't know if it's just a system glitch or if "NOT IN" dragged down the performance...
If there is no second one, the second one is NULL.
But if the first one and the second one are equal, if the code will return any of them?
I made mistake, pay attention to "distinct". Sorry.
@ALEXHANBING good method
@Monicaxt I also want to know, thanks~~~
@tryer3000 your select syntax is beyond my exception.
Note, the Select without From is not standard SQL. Some databases don't support it. It is used here as a trick to generate NULL value if empty result set is returned. But will not work in certain databases, e.g. Oracle
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.