1.grouping sets
1.1
select a, b sum(c) from tbl group by a,b grouping sets((a,b))
相当于 select a,b,sum(c) from tbl group by a,b
1.2
select a,b,sum(c) from tbl group by a,b grouping sets((a,b),a)
相当于
select a,b,sum(c) from tbl group by a,b
union
select a,null ,sum(c) from tbl group by a
1.3
select a,b,sum(c) from tbl group by a,b grouping sets(a,b)
相当于
select a,null,sum(c) from tbl group by a
union
select null ,b,sum(c) from tbl group by b
1.4
select a,b,sum(c) from tbl group by a,b grouping sets((a,b),a,b,())
相当于
select a,b,sum(c) from tbl group by a,b
union
select a,null,sum(c) from tbl group by a
union
select null,b,sum(c) from tbl group by b
union
select null,null,sum(c) from tbl
2.cube 会计算所有group by 列的所有组合
select a,b,c,count(1) from tbl group by a,b,c with cub

本文介绍了Hive中的高级分组聚合操作,包括Grouping Sets、Cube和Rollup。通过实例展示了它们如何简化SQL语句,分别等价于不同的分组组合,并讨论了使用这些功能可能带来的优化和潜在问题,如数据膨胀。
最低0.47元/天 解锁文章
198

被折叠的 条评论
为什么被折叠?



