【Hive报错】Grouping sets aggregations (with rollups or cubes) are not allowed if aggregation function..

最近遇到一个关于Grouping sets的报错,为了不涉密,这边用模拟了一条sql,如下:

报错的sql语句:

select 
    class
    ,info['type'] as type
    ,GROUPING__ID
    ,count(distinct case when info['num'] <> 0 then id end) as cnt
from
    (
    select
        class
        ,info
        ,id
    from table_xxx
    ) a
group by 
    class
    ,info['type']
grouping sets ( (class, info['type']), (class) 

报错信息:

然后报错了:Grouping sets aggregations (with rollups or cubes) are not allowed if aggregation function parameters overlap with the aggregation functions columns

翻译:如果聚合函数参数与聚合函数列重叠,则不允许分组集聚合(使用汇总或多维数据集)

其实就是说 Grouping sets 里面的字段info和sum case when 里面的info字段重叠了,导致报错。

解决方法:

可以把重叠的字段写到子查询里面。

sql如下:

select 
    class
    ,type
    ,GROUPING__ID
    ,count(distinct case when info['num'] <> 0 then id end) as cnt
from
    (
    select
        class
        ,info['type'] as type
        ,info
        ,id
    from table_xxx
    ) a
group by 
    class
    ,type
grouping sets ( (class, type), (class) )

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值