Home >Database >Mysql Tutorial >Oracle ROLLUP和CUBE 用法

Oracle ROLLUP和CUBE 用法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:08:281270browse

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

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn