티스토리 뷰

https://leetcode.com/problems/second-highest-salary

 

Second Highest Salary - LeetCode

Can you solve this real interview question? Second Highest Salary - Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key (column with unique values)

leetcode.com

with base as(
select
    distinct salary
    , dense_rank() over (order by salary desc) rn
from employee
)
, base2 as (
select
    distinct salary
    , rn
    , max(rn) over () mx_rn
from base
)
select 
    if(mx_rn >= 2, salary, null) as SecondHighestSalary
    # salary as SecondHighestSalary
from base2
where if(mx_rn >= 2, rn = 2, rn = 1)
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함