sqlHive选择中间带

rkttyhzu  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(375)

我对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 !="";

但不知道如何计算中位数。

fjaof16o

fjaof16o1#

统计每个客户购买的商品数量
中位数是私人案例百分比= percentile(cnt,0.5) ```
select percentile(cnt,0.5)

from (select count(*) as cnt
from mytable
where Purchased !=""
group by Cust
) t
;

2

相关问题