impala:所有不同的聚合函数都需要有相同的参数集

zrfyljdw  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(559)

我的 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:所有不同的聚合函数都需要与count(distinct color\u key)具有相同的参数集;偏离函数:count(distinct id)
我不知道我为什么会犯这个错误。我所做的是为每一组(按 upload_key ),我试着计算 distinct id 还有多少 distinct color_key .
有人知道吗

lrl1mhuk

lrl1mhuk1#

错误消息表明 DISTINCT 只允许在一列[组合]上使用,但您可以尝试两列, color_key & id . 解决方法是两个选择,然后一个连接:

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

相关问题