아래의 SQL을 실행시키면 결과가 원하는 결과가 나오지 않습니다..
WITH R AS ( SELECT 1 AS X FROM DUAL UNION ALL SELECT 1 AS X FROM DUAL UNION ALL SELECT 1 AS X FROM DUAL UNION ALL SELECT 2 AS X FROM DUAL UNION ALL SELECT 2 FROM DUAL ) SELECT X , GROUPING(X) , COUNT(*) AS CNT , RATIO_TO_REPORT(COUNT(X) ) OVER () * 100 || '%' AS RATIO FROM R GROUP BY ROLLUP(X)
출력값 GROUPING = 1 부분에 100%라는 숫자가 원하는데 50%만 나오는건.. 어케 해결해야 할까요. 원인은 알겠는데..
방법이 떠오르질 않네요..
ㅋㅋㅋ 해결했습니다. 자문 자답이네요.. 부끄럽네요. ㅎㅎ
WITH R AS ( SELECT 1 AS X FROM DUAL UNION ALL SELECT 1 AS X FROM DUAL UNION ALL SELECT 1 AS X FROM DUAL UNION ALL SELECT 2 AS X FROM DUAL UNION ALL SELECT 2 FROM DUAL ) SELECT X , GROUPING(X) , COUNT(*) AS CNT , RATIO_TO_REPORT(COUNT(X) ) OVER (PARTITION BY GROUPING(X)) * 100 || '%' AS RATIO FROM R GROUP BY ROLLUP(X)