Created
March 20, 2023 15:12
-
-
Save khuyentran1401/b9098fd5e3b1df7b16785f39787373c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Write an SQL query to report the second highest salary from the Employee table. If there is no second highest salary, the query should report null. | |
*/ | |
WITH rank_table AS ( | |
SELECT | |
salary, | |
dense_rank() OVER ( | |
order by | |
salary desc | |
) as rnk | |
from | |
employee | |
) | |
select | |
case | |
when max(rnk) = 1 then null | |
else salary | |
end as SecondHighestSalary | |
from | |
rank_table | |
where | |
rnk = 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment