CREATE INDEX IDX_CARD_TRANSACTION
ON CARD_TRANSACTION(CARD_NUM, CARD_TRANSACTION_TIME);
천만건의 데이터 속도가 미친듯이 빨라졌다.
WITH WHOLE AS( SELECT CARD_TRANSACTION_TIME, CARD_TRANSACTION_AMOUNT, CARD_TRANSACTION_CONTENT, INDUSTRY_CODE
FROM CARD_TRANSACTION
WHERE CARD_NUM IN(SELECT CARD_NUM FROM CARD_CONTRACT WHERE RESI_NUM = 9203101937988)
AND TO_CHAR(CARD_TRANSACTION_TIME, 'YYYY') = 2020
AND TO_CHAR(CARD_TRANSACTION_TIME, 'MM') = 01
)
SELECT SUBQUERY1.RESULT AS "i1", SUBQUERY2.RESULT AS "i2", SUBQUERY3.RESULT AS "i3", SUBQUERY4.RESULT AS "i4",
SUBQUERY5.RESULT AS "i5", SUBQUERY6.RESULT AS "i6", SUBQUERY7.RESULT AS "i7", SUBQUERY8.RESULT AS "i8",
SUBQUERY9.RESULT AS "i9", SUBQUERY10.RESULT AS "i10", SUBQUERY11.RESULT AS "i11", SUBQUERY12.RESULT AS "i12",
SUBQUERY13.RESULT AS "i13"
FROM (SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I1')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY1,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I2')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY2,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I3')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY3,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I4')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY4,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I5')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY5,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I6')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY6,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I7')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY7,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I8')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY8,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I9')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY9,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I10')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY10,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I11')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY11,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I12')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY12,
(SELECT *
FROM (SELECT SUM(CARD_TRANSACTION_AMOUNT) AS RESULT
FROM WHOLE
GROUP BY INDUSTRY_CODE
HAVING INDUSTRY_CODE IN('I13')
UNION ALL
-- SELECT NULL AS NUM
SELECT 0 AS RESULT
FROM DUAL)
WHERE RESULT IS NOT NULL OR ROWNUM = 1) SUBQUERY13
WHERE ROWNUM = 1;
'데이터베이스 > ORACLE' 카테고리의 다른 글
[Oracle] 천만 건 업데이트 속도 : 7시간 (0) | 2020.09.26 |
---|---|
[Oracle] SQL 작업 내역 (20.09.23-1) (0) | 2020.09.23 |
[Oracle] ORA-30009: Not enough memory for CONNECT BY operation (0) | 2020.09.13 |
[Oracle] 두 테이블 곱하기 : 길이가 다른 테이블을 from절에 두면, 두개의 테이블이 곱해진다 (랜덤 데이터 생성에 응용) (0) | 2020.09.12 |
[Oracle] n초당 1개의 row만들기 : DATE 하루(86400 건) 만들기 (0) | 2020.09.12 |