WITH a AS
(SELECT 'A' col1,
10 col2
FROM dual
UNION ALL
SELECT 'B' col1,
20 col2
FROM dual
UNION ALL
SELECT 'C' col1,
10 col2
FROM dual
UNION ALL
SELECT 'D' col1,
30 col2
FROM dual)
SELECT col1,
col2,
SUM(decode(col1, 'A',a1+A2,'B',A1+A2,'C',A1+A2+A3)) A
FROM (SELECT col1,
col2,
decode(col1, 'A', col2) a1,
decode(col1, 'B', col2) a2,
decode(col1, 'C', col2) a3
FROM (SELECT col1,
col2
FROM (SELECT substr(a, 1, 1) col1,
substr(a, 2) col2
FROM (SELECT decode(col1, 'A', col1 || col2, 'B', col1 || col2, 'C', col1 || col2) a,
decode(col1, 'A', SUM(col2)) a1,
decode(col1, 'B', SUM(col2)) a2,
decode(col1, 'C', SUM(col2)) a3
FROM a
GROUP BY col1,
col2))
WHERE col1 IS NOT NULL) a)
GROUP BY col1,
col2
-----------------------------------------------------------------------------------------------------------------
COL1 COL2 SUM(DECODE(COL1,'A',A1+A2))
A 10
B 20
C 10
-------------------------------------------------------------------------자 왜 컴럼의 값이 안나오나요?------------------------
정말 이것때문에 열받아 죽겟어요 ㅠㅠ 고수님들 헬플미