gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:51:57 25 4
gpt4 key购买 nike

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);

但是在 hive 中,不可能在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;

它不是最有效的方法,但是这是第一个想到的方法。

关于hadoop - 查询以查找hiveQL中不包括前5%的行的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16936498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com