尚未支持的UDAF' count'在案例陈述中

时间:2018-01-10 18:53:26

标签: sql hive

当我执行以下查询时,我收到错误" count" case语句不支持。想知道是否有解决方法。

    select 
    sum(case when a.key1 == 80 then count(distinct a.key2) else 0 end) as no_80_counts,
    from table1

1 个答案:

答案 0 :(得分:1)

不支持嵌套聚合函数。你过度思考它。

select count(distinct key2) as no_80_counts,
from table1
where key1 = 80

select count(distinct case when key1=80 then key2 end) as no_80_counts,
from table1

删除where子句和group by key1以获取所有key1的不同key2计数。