Second Highest Salary - LeetCode
- code mssql
select isnull( (select distinct salary as SecondHighestSalary from(
select *, dense_rank() over(order by Salary desc) as rnum from Employee) a where rnum=2), null) as SecondHighestSalary
- code mssql
SELECT (SELECT t.Salary
FROM
(SELECT DISTINCT Salary,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS salary_rank
FROM Employee ) t
WHERE t.salary_rank = 2
) AS SecondHighestSalary
- code mysql
SELECT
(SELECT DISTINCT
Salary
FROM
Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 1) AS SecondHighestSalary
;