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))   #偶数
);
原文地址:https://www.cnblogs.com/Tdazheng/p/14922614.html