SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
WareValley
http://www.WareValley.com
Database Audit and Protection [ DB 접근통제 ]
Database Encryption [ DB 암호화 ]
Database Vulnerability Assessment [ DB 취약점 분석 ]
Database SQL Query Approval [ DB 작업결재 ]
Database Performance Monitoring and Management [ DB 성능관리 및 개발 ]
WareValley
Oracle ROLLUP
소계, 합계를 고급지게
오렌지팀 윤석준 선임연구원
Database security and management, WareValley.
http://www.WareValley.com
Query 문제
SELECT * FROM SCOTT.EMP;
 Query 관련 책 이나 동영상을 보면 언제나 빠지지 않고 나오는 단골 문제 :
단계별로 소계, 합계를 구하세요.
단, 같은 Record를 2번 읽지 않게 작성하시오.
각각의 부서별 JOB ( CLERK, MANAGER, ETC )
소계와 합계를 구하세요.
Database security and management, WareValley.
http://www.WareValley.com
흔한 50점짜리 답
SELECT MAX(D.DNAME) AS DEPT,
SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK,
SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER,
SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC,
SUM(E.SAL) AS SUM
FROM SCOTT.EMP E, SCOTT.DEPT D
WHERE E.DEPTNO = D.DEPTNO
GROUP BY E.DEPTNO
UNION ALL
SELECT 'TOTAL',
SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK,
SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER,
SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC,
SUM(E.SAL) AS SUM
FROM SCOTT.EMP E, SCOTT.DEPT D
WHERE E.DEPTNO = D.DEPTNO;
왜 ? 2번 읽었으니깐
Database security and management, WareValley.
http://www.WareValley.com
한번만 읽게 만들려면
• 묻지마 JOIN (catesian product) 를 이용하여 읽은 값을 2개로 복사해서
• 묻지마 JOIN 하면서 TAG 를 1,2 로 둔 다음에
• Inline View로 일단 뽑고
• DECODE 떡칠 신공으로 TAG 별로 야무지게 결과를 나누고,
• AND EXISTS 안에 CHECK 조건의 Inline View를 넣어야 하고
• 아놔~ 안해. 그냥 2번 읽으면 안되 ?
• 그게 그렇게 문제되면 그냥 Server를 한대 더 사던가. 응 ?
Database security and management, WareValley.
http://www.WareValley.com
ROLLUP을 이용한 정답
SELECT DECODE(GROUPING(E.DEPTNO), 1, 'TOTAL', MAX(D.DNAME)) AS DEPT,
SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK,
SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER,
SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC,
SUM(E.SAL) AS SUM,
GROUPING(E.DEPTNO)
FROM SCOTT.EMP E, SCOTT.DEPT D
WHERE E.DEPTNO = D.DEPTNO
GROUP BY ROLLUP(E.DEPTNO);
Database security and management, WareValley.
http://www.WareValley.com
ROLLUP
 Oracle 9i 는 지원하고, 정확히 몇 버전부터 지원되었는지는 모르겠습니다.
 GROUP BY 뒤에 ROLLUP( ) 안에다가 Column들을 넣으면
 해당 Column 들을 통합하지 소계와
 통합한 합계를 순서대로 보여줍니다.
 GROUPING( ) 안에 Column을 넣어주면 집합계산에 참여하지 않으면 1,
참여했으면 0을 반환해 줍니다.
Database security and management, WareValley.
http://www.WareValley.com
ROLLUP e.g.
SELECT DEPTNO,
JOB,
SUM(SAL),
GROUPING(DEPTNO) A,
GROUPING(JOB) B,
GROUPING_ID(DEPTNO,JOB) C
FROM SCOTT.EMP
GROUP BY ROLLUP(DEPTNO, JOB);
Database security and management, WareValley.
http://www.WareValley.com
좀 더 고급지게
SELECT DECODE(GROUPING(E.DEPTNO), 1, 'TOTAL', MAX(D.DNAME)) AS DEPT,
DECODE(GROUPING(E.JOB), 1, 'TOTAL', E.JOB) AS JOB,
SUM(E.SAL) AS SUM,
GROUPING(E.DEPTNO),
GROUPING(E.JOB),
GROUPING_ID(E.DEPTNO, E.JOB)
FROM SCOTT.EMP E, SCOTT.DEPT D
WHERE E.DEPTNO = D.DEPTNO
GROUP BY ROLLUP(E.DEPTNO, E.JOB);
Database security and management, WareValley.
http://www.WareValley.com
Q & A
상세설명 : http://devluna.blogspot.kr/2015/05/oracle-rollup.html

Mais conteúdo relacionado

Destaque

MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB OptimizationJongJin Lee
 
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기복연 이
 
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀EXEM
 
7급 공무원도 쉽게 따라하는 쉘 스크립트
7급 공무원도 쉽게 따라하는 쉘 스크립트7급 공무원도 쉽게 따라하는 쉘 스크립트
7급 공무원도 쉽게 따라하는 쉘 스크립트Young-Ho Cha
 
간단한 쉘 스크립트 작성하기
간단한 쉘 스크립트 작성하기간단한 쉘 스크립트 작성하기
간단한 쉘 스크립트 작성하기licubeclub
 
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도복연 이
 
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략KTH
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1Seok-joon Yun
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝정해 이
 
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝Mungyu Choi
 
성능 좋은 SQL 작성법
성능 좋은 SQL 작성법성능 좋은 SQL 작성법
성능 좋은 SQL 작성법Devgear
 
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표cbs15min
 
[오픈소스컨설팅]MySQL Monitoring
[오픈소스컨설팅]MySQL Monitoring[오픈소스컨설팅]MySQL Monitoring
[오픈소스컨설팅]MySQL MonitoringJi-Woong Choi
 
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법Ji-Woong Choi
 
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, ClusterJi-Woong Choi
 

Destaque (16)

MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB Optimization
 
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 미리보기
 
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀
제 5회 엑셈 수요 세미나 자료 연구컨텐츠팀
 
7급 공무원도 쉽게 따라하는 쉘 스크립트
7급 공무원도 쉽게 따라하는 쉘 스크립트7급 공무원도 쉽게 따라하는 쉘 스크립트
7급 공무원도 쉽게 따라하는 쉘 스크립트
 
간단한 쉘 스크립트 작성하기
간단한 쉘 스크립트 작성하기간단한 쉘 스크립트 작성하기
간단한 쉘 스크립트 작성하기
 
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도
『프로젝트 성패를 결정짓는 데이터 모델링 이야기』 - 구성 지도
 
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략
H3 2011 대형사이트 구축을 위한 MySQL 튜닝전략
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝
 
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
 
MySQL 기초
MySQL 기초MySQL 기초
MySQL 기초
 
성능 좋은 SQL 작성법
성능 좋은 SQL 작성법성능 좋은 SQL 작성법
성능 좋은 SQL 작성법
 
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표
IT는 왜 인문학을 요구하는가? | 최진기 오마이스쿨 대표
 
[오픈소스컨설팅]MySQL Monitoring
[오픈소스컨설팅]MySQL Monitoring[오픈소스컨설팅]MySQL Monitoring
[오픈소스컨설팅]MySQL Monitoring
 
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
 
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster
[오픈소스컨설팅]Day #2 MySQL Tuning, Replication, Cluster
 

Mais de Seok-joon Yun

Retrospective.2020 03
Retrospective.2020 03Retrospective.2020 03
Retrospective.2020 03Seok-joon Yun
 
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterAWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterSeok-joon Yun
 
아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지Seok-joon Yun
 
Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformanceSeok-joon Yun
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07Seok-joon Yun
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06Seok-joon Yun
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05Seok-joon Yun
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04Seok-joon Yun
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03Seok-joon Yun
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02Seok-joon Yun
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01Seok-joon Yun
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptSeok-joon Yun
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsSeok-joon Yun
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++Seok-joon Yun
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2Seok-joon Yun
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4Seok-joon Yun
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료Seok-joon Yun
 

Mais de Seok-joon Yun (20)

Retrospective.2020 03
Retrospective.2020 03Retrospective.2020 03
Retrospective.2020 03
 
Sprint & Jira
Sprint & JiraSprint & Jira
Sprint & Jira
 
Eks.introduce.v2
Eks.introduce.v2Eks.introduce.v2
Eks.introduce.v2
 
Eks.introduce
Eks.introduceEks.introduce
Eks.introduce
 
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterAWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
 
아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지
 
Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, Performance
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threads
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료
 

[Oracle][2015 05-08] Oracle ROLLUP 소계, 합계를 고급지게

  • 1. WareValley http://www.WareValley.com Database Audit and Protection [ DB 접근통제 ] Database Encryption [ DB 암호화 ] Database Vulnerability Assessment [ DB 취약점 분석 ] Database SQL Query Approval [ DB 작업결재 ] Database Performance Monitoring and Management [ DB 성능관리 및 개발 ] WareValley Oracle ROLLUP 소계, 합계를 고급지게 오렌지팀 윤석준 선임연구원
  • 2. Database security and management, WareValley. http://www.WareValley.com Query 문제 SELECT * FROM SCOTT.EMP;  Query 관련 책 이나 동영상을 보면 언제나 빠지지 않고 나오는 단골 문제 : 단계별로 소계, 합계를 구하세요. 단, 같은 Record를 2번 읽지 않게 작성하시오. 각각의 부서별 JOB ( CLERK, MANAGER, ETC ) 소계와 합계를 구하세요.
  • 3. Database security and management, WareValley. http://www.WareValley.com 흔한 50점짜리 답 SELECT MAX(D.DNAME) AS DEPT, SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK, SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER, SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC, SUM(E.SAL) AS SUM FROM SCOTT.EMP E, SCOTT.DEPT D WHERE E.DEPTNO = D.DEPTNO GROUP BY E.DEPTNO UNION ALL SELECT 'TOTAL', SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK, SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER, SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC, SUM(E.SAL) AS SUM FROM SCOTT.EMP E, SCOTT.DEPT D WHERE E.DEPTNO = D.DEPTNO; 왜 ? 2번 읽었으니깐
  • 4. Database security and management, WareValley. http://www.WareValley.com 한번만 읽게 만들려면 • 묻지마 JOIN (catesian product) 를 이용하여 읽은 값을 2개로 복사해서 • 묻지마 JOIN 하면서 TAG 를 1,2 로 둔 다음에 • Inline View로 일단 뽑고 • DECODE 떡칠 신공으로 TAG 별로 야무지게 결과를 나누고, • AND EXISTS 안에 CHECK 조건의 Inline View를 넣어야 하고 • 아놔~ 안해. 그냥 2번 읽으면 안되 ? • 그게 그렇게 문제되면 그냥 Server를 한대 더 사던가. 응 ?
  • 5. Database security and management, WareValley. http://www.WareValley.com ROLLUP을 이용한 정답 SELECT DECODE(GROUPING(E.DEPTNO), 1, 'TOTAL', MAX(D.DNAME)) AS DEPT, SUM(DECODE(E.JOB, 'CLERK', E.SAL, NULL)) AS CLERK, SUM(DECODE(E.JOB, 'MANAGER', E.SAL, NULL)) AS MANAGER, SUM(DECODE(E.JOB, 'CLERK', NULL, 'MANAGER', NULL, SAL)) AS ETC, SUM(E.SAL) AS SUM, GROUPING(E.DEPTNO) FROM SCOTT.EMP E, SCOTT.DEPT D WHERE E.DEPTNO = D.DEPTNO GROUP BY ROLLUP(E.DEPTNO);
  • 6. Database security and management, WareValley. http://www.WareValley.com ROLLUP  Oracle 9i 는 지원하고, 정확히 몇 버전부터 지원되었는지는 모르겠습니다.  GROUP BY 뒤에 ROLLUP( ) 안에다가 Column들을 넣으면  해당 Column 들을 통합하지 소계와  통합한 합계를 순서대로 보여줍니다.  GROUPING( ) 안에 Column을 넣어주면 집합계산에 참여하지 않으면 1, 참여했으면 0을 반환해 줍니다.
  • 7. Database security and management, WareValley. http://www.WareValley.com ROLLUP e.g. SELECT DEPTNO, JOB, SUM(SAL), GROUPING(DEPTNO) A, GROUPING(JOB) B, GROUPING_ID(DEPTNO,JOB) C FROM SCOTT.EMP GROUP BY ROLLUP(DEPTNO, JOB);
  • 8. Database security and management, WareValley. http://www.WareValley.com 좀 더 고급지게 SELECT DECODE(GROUPING(E.DEPTNO), 1, 'TOTAL', MAX(D.DNAME)) AS DEPT, DECODE(GROUPING(E.JOB), 1, 'TOTAL', E.JOB) AS JOB, SUM(E.SAL) AS SUM, GROUPING(E.DEPTNO), GROUPING(E.JOB), GROUPING_ID(E.DEPTNO, E.JOB) FROM SCOTT.EMP E, SCOTT.DEPT D WHERE E.DEPTNO = D.DEPTNO GROUP BY ROLLUP(E.DEPTNO, E.JOB);
  • 9. Database security and management, WareValley. http://www.WareValley.com Q & A 상세설명 : http://devluna.blogspot.kr/2015/05/oracle-rollup.html