rollup 配合 goup by 命令使用,可以提供信息汇总功能(类似于"小计")
下面是一个简单例子:
SQL> select job,deptno,sal from emp;
JOB DEPTNO SAL
--------- --------- ---------
CLERK 20 800
SALESMAN 30 1600
SALESMAN 30 1250
MANAGER 20 2975
SALESMAN 30 1250
MANAGER 30 2850
MANAGER 10 2450
ANALYST 20 3000
PRESIDENT 10 5000
SALESMAN 30 1500
CLERK 20 1100
CLERK 30 950
ANALYST 20 3000
CLERK 10 1300
已选择14行。
SQL> select job,deptno,sum(sal) total_sal from emp group by rollup(job,deptno);
JOB DEPTNO TOTAL_SAL
--------- --------- ---------
ANALYST 20 6000
ANALYST 6000
CLERK 10 1300
CLERK 20 1900
CLERK 30 950
CLERK 4150
MANAGER 10 2450
MANAGER 20 2975
MANAGER 30 2850
MANAGER 8275
PRESIDENT 10 5000
PRESIDENT 5000
SALESMAN 30 5600
SALESMAN 5600
29025
下面是一个简单例子:
SQL> select job,deptno,sal from emp;
JOB DEPTNO SAL
--------- --------- ---------
CLERK 20 800
SALESMAN 30 1600
SALESMAN 30 1250
MANAGER 20 2975
SALESMAN 30 1250
MANAGER 30 2850
MANAGER 10 2450
ANALYST 20 3000
PRESIDENT 10 5000
SALESMAN 30 1500
CLERK 20 1100
CLERK 30 950
ANALYST 20 3000
CLERK 10 1300
已选择14行。
SQL> select job,deptno,sum(sal) total_sal from emp group by rollup(job,deptno);
JOB DEPTNO TOTAL_SAL
--------- --------- ---------
ANALYST 20 6000
ANALYST 6000
CLERK 10 1300
CLERK 20 1900
CLERK 30 950
CLERK 4150
MANAGER 10 2450
MANAGER 20 2975
MANAGER 30 2850
MANAGER 8275
PRESIDENT 10 5000
PRESIDENT 5000
SALESMAN 30 5600
SALESMAN 5600
29025
已选择15行。
本文转自茄子_2008,原文链接:http://www.cnblogs.com/xd502djj/archive/2010/09/21/1832191.html,如需转载请自行联系原作者