-- 기사논조
SELECT (SELECT CODE_NM
FROM S_CODE_MANAGER
WHERE CODE_GROUP = 'to'
AND CODE = A.TONE_CD) AS TONE_NM,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '01', 1)) AS JANUARY,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '02', 1)) AS FEBRUARY,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '03', 1)) AS MARCH,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '04', 1)) AS APRIL,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '05', 1)) AS MAY,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '06', 1)) AS JUNE,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '07', 1)) AS JULY,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '08', 1)) AS AUGUST,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '09', 1)) AS SEPTEMBER,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '10', 1)) AS OCTOBER,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '11', 1)) AS NOVEMBER,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '12', 1)) AS DECEMBER,
COUNT (*) AS TOTAL
FROM S_ARTICLE A
WHERE A.PUBLISH_DT LIKE '2007%'
GROUP BY TONE_CD
UNION ALL
-- 기사소스
SELECT (SELECT CODE_NM
FROM S_CODE_MANAGER
WHERE CODE_GROUP = 'so'
AND CODE = A.SOURCE_CD) AS SOURCE_NM,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '01', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '02', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '03', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '04', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '05', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '06', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '07', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '08', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '09', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '10', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '11', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '12', 1)),
COUNT (*)
FROM S_ARTICLE A
WHERE A.PUBLISH_DT LIKE '2007%'
GROUP BY SOURCE_CD
UNION ALL
-- 기사유형
SELECT (SELECT CODE_NM
FROM S_CODE_MANAGER
WHERE CODE_GROUP = 'ty'
AND CODE = A.TYPE_CD) AS TYPE_NM,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '01', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '02', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '03', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '04', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '05', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '06', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '07', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '08', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '09', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '10', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '11', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '12', 1)),
COUNT (*)
FROM S_ARTICLE A
WHERE A.PUBLISH_DT LIKE '2007%'
GROUP BY TYPE_CD
UNION ALL
-- 기사주제
SELECT (SELECT CODE_NM
FROM S_CODE_MANAGER
WHERE CODE_GROUP = 'su'
AND CODE = A.SUBJECT_CD) AS SUBJECT_NM,
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '01', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '02', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '03', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '04', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '05', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '06', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '07', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '08', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '09', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '10', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '11', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '12', 1)),
COUNT (*)
FROM S_ARTICLE A
WHERE A.PUBLISH_DT LIKE '2007%'
GROUP BY SUBJECT_CD
UNION ALL
-- 총계
SELECT 'TOTAL',
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '01', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '02', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '03', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '04', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '05', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '06', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '07', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '08', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '09', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '10', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '11', 1)),
COUNT (DECODE (SUBSTR (A.PUBLISH_DT, 5, 2), '12', 1)),
COUNT (*)
FROM S_ARTICLE A
WHERE A.PUBLISH_DT LIKE '2007%'
이와 같이 중복되는 쿼리인데요~
이걸 중복되는 부분을 줄이고 할 수 있는 방법은 있을까요?
아직 제가 초보라서 이런식으로 밖에 안되는군요~
고수님들의 많은 답변 부탁드립니다..
아침저녁으로 쌀쌀한데.. 오라클럽회원님들.. 감기 조심하세요~ ^^*