-_- 이걸 왜 알려고 하시지..ㅋㅋㅋ 0 3 4,122

by 호야 GROUPING CUBE [2008.10.02 16:19:44]


WITH TEST AS (
SELECT '1' CLASS, 'ACCOUNTING' DNAME,'CLERK' JOB,1300 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'ACCOUNTING' DNAME,'MANAGER' JOB,2450 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'ACCOUNTING' DNAME,'PRESIDENT' JOB,5000 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'ANALYST' JOB,6000 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'CLERK' JOB,1900 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'MANAGER' JOB,2975 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'SALES' DNAME,'MANAGER' JOB,28500 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'SALES' DNAME,'SALESMAN' JOB,4000 SAL FROM DUAL
)
SELECT CLASS, DNAME,JOB,SUM(SAL)
FROM TEST
GROUP BY CLASS,CUBE(DNAME,JOB)
HAVING GROUPING(DNAME)||GROUPING(JOB)<>'11'
ORDER BY GROUPING(DNAME)||GROUPING(JOB).

 

결과

----------------------------------------------------

CL DNAME                     JOB                  SUM(SAL)
-- --------------------      ------------------        ----------
1  RESEARCH             CLERK                    1900
1  RESEARCH             ANALYST                 6000
1  RESEARCH             MANAGER               2975
1  ACCOUNTING           MANAGER             2450
2  SALES                        SALESMAN            4000
2  ACCOUNTING           PRESIDENT         5000
2  SALES                        MANAGER            28500
1  ACCOUNTING           CLERK                   1300
1  RESEARCH                                              10875
1  ACCOUNTING                                            3750
2  ACCOUNTING                                            5000
2  SALES                                                        32500
1                                          CLERK                 3200
1                                       ANALYST                6000
2                                   SALESMAN                4000
2                                 PRESIDENT                5000
2                                     MANAGER              28500
1                                     MANAGER                5425

요런 결과가 나오네요..^^: 설명은 강좌 란에... 

by 호야 [2008.10.02 17:31:40]
-_- 저기 위에 있는 UNION ALL 은 가상 테이블 만들려고
WITH 절 써서 가상의 데이터를 넣어 논거인데요...
실제 적으로 쓰일 구문은
SELECT CLASS, DNAME,JOB,SUM(SAL)
FROM TEST
GROUP BY CLASS,CUBE(DNAME,JOB)
HAVING GROUPING(DNAME)||GROUPING(JOB)<>'11'
ORDER BY GROUPING(DNAME)||GROUPING(JOB).

이것밖에는 없는뎅.. 유니온 안 썼는데욤

by 호야 [2008.10.02 17:36:26]
-_- 제가 장난끼가 많은 나이라..ㅠ.ㅠ 죄송합니다...
정중히 사과 드립니다.. (_ _)

by 글쓴이 [2008.10.02 17:43:34]
죄송해요..;; 제가 자세히 안보고 유니온 쥬르륵 보고 울컥했어요..
여튼 감사해요~ 대략 답이나올것같네요^^;
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입