LeetCode 【困难】数据库-第569:员工薪水中位数


select Id, Company, Salary
from
(
    select *, row_number() over (partition by Company order by Salary) rnk,
    count(*) over (partition by Company) count_num
    from Employee
) a
where
(
	(count_num%2=1 and rnk = (count_num+1)/2)   # 奇数
or
	(count_num%2=0 and (rnk = count_num/2 or rnk = (count_num/2)+1))   #偶数
);
posted @ 2021-06-23 14:29  hangover  阅读(81)  评论(0编辑  收藏  举报