问题描述
我有一个配置单元表,
name age sal
A 45 1222
B 50 4555
c 44 8888
D 78 1222
E 12 7888
F 23 4555
我想计算年龄中位数列。
以下是我的做法
<$ p $ (年龄)为HMAX,计数(年龄)为HCount,
IF(计数(年龄)%2 = 0,'偶数','奇数')作为PCOUNT
从v_act_subjects_bh;
欣赏任何查询建议
您可以使用百分位数函数来计算中位数。试试这个: I have a hive table, I want to calculate median of age column. Below is my approach Appreciate any query suggestion You can use the percentile function to compute the median. Try this: 这篇关于如何计算Hive中的中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
pre $ 从table_name
$ c $选择百分比(cast(age as BIGINT),0.5) c> name age sal
A 45 1222
B 50 4555
c 44 8888
D 78 1222
E 12 7888
F 23 4555
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;
select percentile(cast(age as BIGINT), 0.5) from table_name