Oracle ROLLUP和CUBE 用法

2014-11-24 18:41:24 · 作者: · 浏览: 0

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