目录
- Grouping Sets
指定多种聚合的维度、层次,对多个group by + union all进行替换、简化
- With Rollup
可实现从右到左递减多级的统计,显示统计某一层次结构的聚合
- With cube
可以实现多个任意维度的查询,会统计所选列中值的所有组合的聚合
- Grouping__id
按照一定规则给统计的各维度组合打标,并返回标识值。
1. Group by扩展——Grouping Sets
简要说明:在一个 group by 查询中,根据不同的维度组合进行聚合,等价于将不同维度的 group by 结果集进行 union all。
样例HIVE-SQL:
SELECT col1, col2, col3 , sum(income) as income, count(distinct user_id) as user_qtty FROM dw.table_name WHERE month_id = '201912' GROUP BY col1, col2, col3 GROUPING SETS(col1,(col1,col2),(col1,col2,col3));
|
执行结果展示:
Col1 |
Col2 |
Col3 |
income |