Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

8,639 views

Published on

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

Published in: Software
  • Sex in your area is here: ❤❤❤ http://bit.ly/2Qu6Caa ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❤❤❤ http://bit.ly/2Qu6Caa ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ACCESS that WEBSITE Over for All Ebooks (Unlimited) ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... DOWNLOAD FULL EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • (Unlimited)....ACCESS WEBSITE Over for All Ebooks ................ accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

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

  1. 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. 2. Database security and management, WareValley. http://www.WareValley.com Query 문제 SELECT * FROM SCOTT.EMP;  Query 관련 책 이나 동영상을 보면 언제나 빠지지 않고 나오는 단골 문제 : 단계별로 소계, 합계를 구하세요. 단, 같은 Record를 2번 읽지 않게 작성하시오. 각각의 부서별 JOB ( CLERK, MANAGER, ETC ) 소계와 합계를 구하세요.
  3. 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. 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. 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. 6. Database security and management, WareValley. http://www.WareValley.com ROLLUP  Oracle 9i 는 지원하고, 정확히 몇 버전부터 지원되었는지는 모르겠습니다.  GROUP BY 뒤에 ROLLUP( ) 안에다가 Column들을 넣으면  해당 Column 들을 통합하지 소계와  통합한 합계를 순서대로 보여줍니다.  GROUPING( ) 안에 Column을 넣어주면 집합계산에 참여하지 않으면 1, 참여했으면 0을 반환해 줍니다.
  7. 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. 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. 9. Database security and management, WareValley. http://www.WareValley.com Q & A 상세설명 : http://devluna.blogspot.kr/2015/05/oracle-rollup.html

×