当我执行以下查询时,我收到错误" count" case语句不支持。想知道是否有解决方法。
select
sum(case when a.key1 == 80 then count(distinct a.key2) else 0 end) as no_80_counts,
from table1
答案 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计数。