【问题标题】:Not yet supported place for UDAF 'count' in CASE statmentsCASE 语句中尚不支持 UDAF 'count' 的位置
【发布时间】:2018-01-10 18:53:26
【问题描述】:

当我执行下面的查询时,我得到错误 "count" is not supported in case statements。想知道是否有解决此问题的方法。

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

【问题讨论】:

  • 不支持嵌套聚合函数。你到底想做什么?
  • 对于特定的 key1 值,我试图计算不同的 key2,因为 key1 可以与多个 key2 相关联

标签: sql hive


【解决方案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 计数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    相关资源
    最近更新 更多