众数:
select *
from (select salary,
repeat_num,
dense_rank() over(order by repeat_num desc) rank_repeat_num
from (select salary, count(*) repeat_num
from employees
group by salary))
where rank_repeat_num = 1;
中位数
select avg(salary)
from (select salary,
row_number() over(order by salary) rn,
count(*) over() total
from emp)
where (mod(total,2)=1 and rn=(total+1)/2) or (mod(total,2)=0 and rn in (total/2,total/2+1));
众数,中位数
最新推荐文章于 2024-10-11 00:15:00 发布