gpt4 book ai didi

hadoop - Hive:查找前 20% 的记录

转载 作者:可可西里 更新时间:2023-11-01 16:35:24 25 4
gpt4 key购买 nike

我有一些数据,例如:-

ID  PRICE
1 100
2 200
3 120
4 130
5 320
6 300
7 200
8 100
9 120
10 250

我需要找到最高 20% 的价格。

预期输出:-

ID  PRICE
5 320
6 300

最佳答案

你可以在没有连接的情况下做到这一点。使用解析函数计算max(price),取80%,然后使用filter price>80%:

with your_data as ( --this is your data
select stack(10,
1 , 100,
2 , 200,
3 , 120,
4 , 130,
5 , 320,
6 , 300,
7 , 200,
8 , 100,
9 , 120,
10, 250) as (ID, PRICE)
)

select id, price
from
(
select d.*, max(price) over()*0.8 as pct_80 from your_data d
)s where price>pct_80

结果:

OK
id price
6 300
5 320

使用您的表而不是 WITH 子查询,如有必要,按 ID 添加订单。

关于hadoop - Hive:查找前 20% 的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54619056/

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