WITH RTOTAL AS
(
SELECT MAIN_SEQ, COUNT(MAIN_SEQ) AS TOT
FROM S_REPLY
GROUP BY MAIN_SEQ
)
SELECT M.MAIN_SEQ, M.SUB_SEQ, M.IKEY, M.INAME, M.GNAME, NVL(R.CNT, 0) AS CNT, NVL(T.TOT, 0) AS TOT, ROUND((NVL(R.CNT, 0)/NVL(T.TOT, 0))*100, 1) AS RND, M.SORT
FROM S_QUEST_MULTI M
,(
SELECT IDX, QIDX, EX_SPLIT, COUNT(EX_SPLIT) AS CNT
FROM (
SELECT IDX, QIDX, MEMBER_ID, REGEXP_SUBSTR(R.EX, '[^\;]+', 1, L.LEV) AS EX_SPLIT
FROM
(
SELECT IDX, QIDX, MEMBER_ID, EX, REGEXP_COUNT(EX, '\;') AS CNT
FROM S_REPLY
) R
,(
SELECT LEVEL AS LEV
FROM DUAL
CONNECT BY LEVEL <= 100
) L
WHERE L.LEV <= R.CNT
)
GROUP BY IDX, QIDX, EX_SPLIT
) R
,RTOTAL T
WHERE M.MAIN_SEQ = R.IDX(+)
AND M.SUB_SEQ = R.QIDX(+)
AND M.IKEY = R.EX_SPLIT(+)
AND M.MAIN_SEQ = T.MAIN_SEQ(+)
ORDER BY M.MAIN_SEQ, M.SUB_SEQ, M.SORT, M.IKEY;
'데이타베이스(DB) > ORACLE' 카테고리의 다른 글
ORACLE 에러 - ORA-12519: TNS:no appropriate service handler found (0) | 2016.03.03 |
---|---|
ORACLE 에러 - ORA-00020: 최대 프로세스 (150) 수를 초과했습니다. (0) | 2016.03.03 |
ORACLE 에러 - ORA-06413: 연결이 개방되지 않았습니다. (0) | 2016.01.13 |
테이블 정보 조회 쿼리 (0) | 2014.07.02 |
ORACLE 에러 - ORA-01465: 16진수의 지정이 부적합합니다 (0) | 2014.07.01 |