Oracle ROLLUP和CUBE 用法
程序员文章站
2024-04-04 11:47:47
...
CUBE和ROLLUP ROLLUP是oracle8i以来一个新的SQL关键字,9i ,-11G不新鲜了,它是对GROUP BY子句的扩充,允许在SELECT语句中计算不
CUBE和ROLLUP ROLLUP是Oracle8i以来一个新的SQL关键字,9i ,-11G不新鲜了,它是对GROUP BY子句的扩充,,允许在SELECT语句中计算不同层次的小计。
CUBE是对GROUP BY子句的另外一 种扩充,它允许计算所有小计可能的组合,用来生成各种汇总报表。
以下介绍他们的用法
select B,c,D from Atest group by rollup(B,C,D);
相当于
select B,c,D from Atest group by B,C,D;
union all
select B,c,null from Atest group by B,C
union all
select B,null,null from Atest group by B
select B,c from Atest group by cube(B,C);
将所有 (B,C)组合的子集group by合并
相当于
select B,c from Atest group by B,C
union all
select B,null from Atest group by B
union all
select null,c from Atest group by c
union all
select null,null from Atest group by null