Hive是全新的,我有一个像这样的数据库:
Cust | Visited | Purchased
--------------------------------
id01 | Novem | Computer
id02 | March | Printer
id03 | Decem | [empty]
id01 | April | Phone
id02 | Augus | Laptop
id01 | Januar| Monitor
id01 | Febr | [empty]
id03 | Septem| Keyboard
您能帮我找出每位客户购买商品的中位数吗?
至于平均水平,我想我可以做到以下几点:
select count(*) / count(distinct(Cust)) from table where Purchased !="";
但不确定如何计算中位数。
答案 0 :(得分:1)
percentile(cnt,0.5)
select percentile(cnt,0.5)
from (select count(*) as cnt
from mytable
where Purchased !=""
group by Cust
) t
;
2.0