[英]Query to find the average of the rows excluding the top 5% in hiveQL
select perecentile(time,0.95) from sometable;
gives the 95th percentile.
我想要時間值低於此值的所有行的平均值。
在甲骨文中將是這樣的:
select avg(time) from sometable
where
time<(select percentile(time,0.95) from sometable);
但是在蜂巢中,不可能在where子句中使用子查詢。當我使用union時,我無法隔離需要與其他元組進行比較的元組。
您可以對百分比結果進行笛卡爾聯接,然后過濾所有較小的值。
像這樣的東西:
select avg(time) from sometable a
join (select percentile(time,0.95) perc from sometable) b on (1=1)
where a.time < b.perc;
它不是最有效的方法,但是這是第一個想到的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.