so_gubun 조회를 빼먹었었네요. 수정했습니다.
WITH temp AS
(
SELECT 1 no, '19990601' uncash_date, '1' so_gubun, 100 bill_amt, 'TEST1' cust_name FROM dual
UNION ALL SELECT 2, '19990601', '2', 200, 'TEST2' FROM dual
UNION ALL SELECT 3, '19990601', '1', 300, 'TEST3' FROM dual
UNION ALL SELECT 4, '19990601', '2', 400, 'TEST4' FROM dual
UNION ALL SELECT 5, '19990602', '1', 500, 'TEST5' FROM dual
UNION ALL SELECT 6, '19990602', '1', 600, 'TEST6' FROM dual
UNION ALL SELECT 7, '19990602', '1', 700, 'TEST7' FROM dual
UNION ALL SELECT 8, '19990603', '2', 800, 'TEST8' FROM dual
UNION ALL SELECT 9, '19990603', '2', 900, 'TEST9' FROM dual
)
SELECT CASE GROUPING_ID(4,3,uncash_date,2,1,no)
WHEN 0 THEN uncash_date
WHEN 1 THEN '1계'
WHEN 3 THEN '2계'
WHEN 7 THEN '합계'
WHEN 15 THEN '총1계'
WHEN 31 THEN '총2계'
WHEN 63 THEN '총합계'
END AS uncash_date
, so_gubun
, CASE GROUPING_ID(4,3,uncash_date,2,1,no)
WHEN 0 THEN SUM(bill_amt)
WHEN 1 THEN SUM(DECODE(so_gubun,1,bill_amt))
WHEN 3 THEN SUM(DECODE(so_gubun,2,bill_amt))
WHEN 7 THEN SUM(bill_amt)
WHEN 15 THEN SUM(DECODE(so_gubun,1,bill_amt))
WHEN 31 THEN SUM(DECODE(so_gubun,2,bill_amt))
WHEN 63 THEN SUM(bill_amt)
END AS bill_amt
, cust_name
FROM temp
GROUP BY ROLLUP(4, 3, uncash_date, 2, 1, (no, so_gubun, cust_name))
;