我对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 !="";
但不知道如何计算中位数。
1条答案
按热度按时间fjaof16o1#
统计每个客户购买的商品数量
中位数是私人案例百分比=
percentile(cnt,0.5)
```select percentile(cnt,0.5)
from (select count(*) as cnt
from mytable
where Purchased !=""
group by Cust
) t
;