gpt4 book ai didi

sql - Impala:所有 DISTINCT 聚合函数都需要具有相同的参数集

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

我的 Impala 查询中出现以下错误:

select 
upload_key,
max(my_timestamp) as upload_time,
max(color_key) as max_color_fk,
count(distinct color_key) as color_count,
count(distinct id) as toy_count
from upload_table
group by upload_key

并得到错误:

AnalysisException: all DISTINCT aggregate functions need to have the same set of parameters as count(DISTINCT color_key); deviating function: count(DISTINCT id)



我不确定为什么会出现此错误。我所做的是对每个组(按 upload_key 分组),我试图计算有多少 distinct id以及多少 distinct color_key .
有谁有想法吗

最佳答案

错误消息表明 DISTINCT只允许一列[组合],但你尝试两列,color_key & id .解决方法是两个 Selects 然后一个 join:

select
t1.upload_key,
t1.upload_time,
t1.max_color_fk,
t1.color_count,
t2.toy_count
from
(
select
upload_key,
max(my_timestamp) as upload_time,
max(color_key) as max_color_fk,
count(distinct color_key) as color_count
from upload_table
group by upload_key
) as t1
join
(
select
upload_key
count(distinct id) as toy_count
from upload_table
group by upload_key
) as t2
on t1. upload_key = t2.upload_key

关于sql - Impala:所有 DISTINCT 聚合函数都需要具有相同的参数集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39236076/

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