如何计算 Hive 中的中位数 [英] How to calculate median in Hive
本文介绍了如何计算 Hive 中的中位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张蜂巢表,
name age sal
A 45 1222
B 50 4555
c 44 8888
D 78 1222
E 12 7888
F 23 4555
我想计算年龄列的中位数.
I want to calculate median of age column.
下面是我的方法
select min(age) as HMIN,max(age) as HMAX,count(age) as HCount,
IF(count(age)%2=0,'even','Odd') as PCOUNT
from v_act_subjects_bh;
感谢任何查询建议
推荐答案
您可以使用百分位函数来计算中位数.试试这个:
You can use the percentile function to compute the median. Try this:
select percentile(cast(age as BIGINT), 0.5) from table_name
这篇关于如何计算 Hive 中的中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文