[Developer] Rollup
rollup(a,b,c)=group by a,b,c + group by a,b + group by a + group by null
rollup(a,b)=group a,b + group by a + group by null
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ------------------------------ --------------- ---------- --------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- ------------------------ ---------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> list
1 select b.dname,a.job,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by rollup(b.dname,a.job)
SQL> /
DNAME JOB SUM(SAL)
------------------------------------------ --------------------------- ----------
SALES CLERK 950
SALES MANAGER 2850
SALES SALESMAN 5600
SALES 9400
RESEARCH CLERK 1900
RESEARCH ANALYST 6000
RESEARCH MANAGER 2975
RESEARCH 10875
ACCOUNTING CLERK 1300
ACCOUNTING MANAGER 2450
ACCOUNTING PRESIDENT 5000
ACCOUNTING 8750
29025
可以改變rollup中的順序,得到不同報表。
SQL> edit
Wrote file afiedt.buf
1 select a.job,b.dname,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by rollup(a.job,b.dname)
SQL> /
JOB DNAME SUM(SAL)
--------------------------- ------------------------ ----------
CLERK SALES 950
CLERK RESEARCH 1900
CLERK ACCOUNTING 1300
CLERK 4150
ANALYST RESEARCH 6000
ANALYST 6000
MANAGER SALES 2850
MANAGER RESEARCH 2975
MANAGER ACCOUNTING 2450
MANAGER 8275
SALESMAN SALES 5600
SALESMAN 5600
PRESIDENT ACCOUNTING 5000
PRESIDENT 5000
29025
15 rows selected.
可以進行例外rollup
SQL> edit
Wrote file afiedt.buf
1 select b.dname,a.job,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by b.dname,rollup(a.job)
SQL> /
DNAME JOB SUM(SAL)
------------------------ --------------------------- ----------
SALES CLERK 950
SALES MANAGER 2850
SALES SALESMAN 5600
SALES 9400
RESEARCH CLERK 1900
RESEARCH ANALYST 6000
RESEARCH MANAGER 2975
RESEARCH 10875
ACCOUNTING CLERK 1300
ACCOUNTING MANAGER 2450
ACCOUNTING PRESIDENT 5000
ACCOUNTING 8750
12 rows selected.
SQL> edit
Wrote file afiedt.buf
1 select to_char(a.hiredate,'yyyy') hiredate,b.dname,a.job,sum(a.sal)
2 from emp a,dept b
3 where a.deptno=b.deptno
4* group by rollup(to_char(a.hiredate,'yyyy'),b.dname,a.job)
SQL> /
HIREDATE DNAME JOB SUM(A.SAL)
--------------- ------------------------ --------------------------- ----------
1980 RESEARCH CLERK 800
1980 RESEARCH 800
1980 800
1981 SALES CLERK 950
1981 SALES MANAGER 2850
1981 SALES SALESMAN 5600
1981 SALES 9400
1981 RESEARCH ANALYST 3000
1981 RESEARCH MANAGER 2975
1981 RESEARCH 5975
1981 ACCOUNTING MANAGER 2450
1981 ACCOUNTING PRESIDENT 5000
1981 ACCOUNTING 7450
1981 22825
1982 ACCOUNTING CLERK 1300
1982 ACCOUNTING 1300
1982 1300
1987 RESEARCH CLERK 1100
1987 RESEARCH ANALYST 3000
1987 RESEARCH 4100
1987 4100
29025
22 rows selected.
rollup(a,b)=group a,b + group by a + group by null
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ------------------------------ --------------- ---------- --------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- ------------------------ ---------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> list
1 select b.dname,a.job,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by rollup(b.dname,a.job)
SQL> /
DNAME JOB SUM(SAL)
------------------------------------------ --------------------------- ----------
SALES CLERK 950
SALES MANAGER 2850
SALES SALESMAN 5600
SALES 9400
RESEARCH CLERK 1900
RESEARCH ANALYST 6000
RESEARCH MANAGER 2975
RESEARCH 10875
ACCOUNTING CLERK 1300
ACCOUNTING MANAGER 2450
ACCOUNTING PRESIDENT 5000
ACCOUNTING 8750
29025
可以改變rollup中的順序,得到不同報表。
SQL> edit
Wrote file afiedt.buf
1 select a.job,b.dname,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by rollup(a.job,b.dname)
SQL> /
JOB DNAME SUM(SAL)
--------------------------- ------------------------ ----------
CLERK SALES 950
CLERK RESEARCH 1900
CLERK ACCOUNTING 1300
CLERK 4150
ANALYST RESEARCH 6000
ANALYST 6000
MANAGER SALES 2850
MANAGER RESEARCH 2975
MANAGER ACCOUNTING 2450
MANAGER 8275
SALESMAN SALES 5600
SALESMAN 5600
PRESIDENT ACCOUNTING 5000
PRESIDENT 5000
29025
15 rows selected.
可以進行例外rollup
SQL> edit
Wrote file afiedt.buf
1 select b.dname,a.job,sum(sal) from emp a,dept b
2 where a.deptno=b.deptno
3* group by b.dname,rollup(a.job)
SQL> /
DNAME JOB SUM(SAL)
------------------------ --------------------------- ----------
SALES CLERK 950
SALES MANAGER 2850
SALES SALESMAN 5600
SALES 9400
RESEARCH CLERK 1900
RESEARCH ANALYST 6000
RESEARCH MANAGER 2975
RESEARCH 10875
ACCOUNTING CLERK 1300
ACCOUNTING MANAGER 2450
ACCOUNTING PRESIDENT 5000
ACCOUNTING 8750
12 rows selected.
SQL> edit
Wrote file afiedt.buf
1 select to_char(a.hiredate,'yyyy') hiredate,b.dname,a.job,sum(a.sal)
2 from emp a,dept b
3 where a.deptno=b.deptno
4* group by rollup(to_char(a.hiredate,'yyyy'),b.dname,a.job)
SQL> /
HIREDATE DNAME JOB SUM(A.SAL)
--------------- ------------------------ --------------------------- ----------
1980 RESEARCH CLERK 800
1980 RESEARCH 800
1980 800
1981 SALES CLERK 950
1981 SALES MANAGER 2850
1981 SALES SALESMAN 5600
1981 SALES 9400
1981 RESEARCH ANALYST 3000
1981 RESEARCH MANAGER 2975
1981 RESEARCH 5975
1981 ACCOUNTING MANAGER 2450
1981 ACCOUNTING PRESIDENT 5000
1981 ACCOUNTING 7450
1981 22825
1982 ACCOUNTING CLERK 1300
1982 ACCOUNTING 1300
1982 1300
1987 RESEARCH CLERK 1100
1987 RESEARCH ANALYST 3000
1987 RESEARCH 4100
1987 4100
29025
22 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2016064/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- HbuilderX,找不到rollup/rollup-win32-x64-msvcUIWin32
- MySQL 中 WITH ROLLUP 用法MySql
- rollup配置及使用
- 使用 rollup 打包 JSJS
- 使用Rollup打包JavaScriptJavaScript
- pl developerDeveloper
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)ErrorDeveloper
- Oracle OCP(12):ROLLUP & CUBEOracle
- 關於Rollup那些事
- rollup入門介紹
- PLSQL Developer 14SQLDeveloper
- rollup 開發環境搭建開發環境
- 其他打包工具 Rollup && Parcel
- PLSQL Developer 行號SQLDeveloper
- PLSQL Developer配置使用SQLDeveloper
- 10分鐘快速精通rollup.js——前置學習之rollup.js外掛篇JS
- 以太坊Rollup方案之 arbitrum(2)
- 以太坊Rollup方案之 arbitrum(1)
- Rollup的本質是什麼?
- 5分鐘打通rollup.js副本JS
- 元件庫rollup打包體積優化元件優化
- plsql developer 視窗的使用SQLDeveloper
- PLSQL Developer 12 註冊碼SQLDeveloper
- 打包工具 rollup.js 入門教程JS
- vite的專案,使用 rollup 打包的方法Vite
- 10分鐘快速進階rollup.jsJS
- 使用rollup打包庫的一種基本配置
- 10分鐘快速入門rollup.jsJS
- 記錄從vuecli打包庫遷移到rollup打包Vue
- 解析數倉OLAP函式:ROLLUP、CUBE、GROUPING SETS函式
- Rollup作者新作: Svelte Cubed, 擁抱 Three.js !JS
- plsql developer 15的安裝配置SQLDeveloper
- plsql developer工具生成sql monitor reportSQLDeveloper
- 配置PLSQL Developer詳細步驟SQLDeveloper
- MySQL資料庫中的分組函式ROLLUPMySql資料庫函式
- Rollup處理並打包JS檔案專案例項JS
- AI UI developer by ChatGPT plugin:Tailwind CSS BuilderAIUIDeveloperChatGPTPluginCSS
- Iridient Developer for macRAW影像調整軟體DeveloperMac
- MySQL8.0-分組函式ROLLUP的基本用法(GROUPING)MySql函式