0
点赞
收藏
分享

微信扫一扫

Leetcode_569_员工薪水中位数_SQL

软件共享软件 2022-02-15 阅读 56
with t as (
    select id, company, salary, row_number() over(partition by company order by salary) as 'rk', count(id) over(partition by company) as 'cnt'
    from Employee
)

select id, company, salary
from t
where rk >= cnt / 2 and rk <= cnt / 2 + 1

不算难吧,如果用函数的话,很有意思的事,中位数这个问题通过cnt和rank的大小来决定是一个还是两个,这个点想到了应该没什么难度

举报

相关推荐

0 条评论