ITPub博客

首页 > 数据库 > Oracle > [Developer] Cube

[Developer] Cube

原创 Oracle 作者:tolilong 时间:2016-04-12 16:08:43 0 删除 编辑
cube(a,b)     统计列包含:group(a,b)+group(a)+group(b)+group()
cube(a,b,c)   统计列包含:(a,b,c)+group(a,b)+group(a,c)+group(b,c)+group(a)+group(b)+group(c)+group()
……以此类推ing……


cube分组级别更多,结果更精细 
SQL> edit
Wrote file afiedt.buf

  1  select b.dname,a.job,sum(sal)
  2  from emp a,dept b
  3  where a.deptno=b.deptno
  4  group by cube(b.dname,a.job)
  5* order by 1
SQL> /

DNAME                    JOB               SUM(SAL)
------------------------ --------------- ----------
ACCOUNTING               CLERK                 1300
ACCOUNTING               MANAGER               2450
ACCOUNTING               PRESIDENT             5000
ACCOUNTING                                     8750
RESEARCH                 ANALYST               6000
RESEARCH                 CLERK                 1900
RESEARCH                 MANAGER               2975
RESEARCH                                      10875
SALES                    CLERK                  950
SALES                    MANAGER               2850
SALES                    SALESMAN              5600
SALES                                          9400
                         ANALYST               6000
                         CLERK                 4150
                         MANAGER               8275
                         PRESIDENT             5000
                         SALESMAN              5600
                                              29025

18 rows selected.

部分cube,提出合计和group by job.
SQL> edit
Wrote file afiedt.buf

  1  select b.dname,a.job,sum(sal)
  2  from emp a,dept b
  3  where a.deptno=b.deptno
  4  group by b.dname,cube(a.job)
  5* order by 1
SQL> /

DNAME                    JOB               SUM(SAL)
------------------------ --------------- ----------
ACCOUNTING               CLERK                 1300
ACCOUNTING               MANAGER               2450
ACCOUNTING               PRESIDENT             5000
ACCOUNTING                                     8750
RESEARCH                 ANALYST               6000
RESEARCH                 CLERK                 1900
RESEARCH                 MANAGER               2975
RESEARCH                                      10875
SALES                    CLERK                  950
SALES                    MANAGER               2850
SALES                    SALESMAN              5600
SALES                                          9400


12 rows selected.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-2079837/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208675