繁体   English   中英

查询以查找hiveQL中不包括前5%的行的平均值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM