WITH t AS ( SELECT 1 id, 'a' cd, 10 v FROM dual UNION ALL SELECT 2, 'a', 20 FROM dual UNION ALL SELECT 3, 'b', 10 FROM dual UNION ALL SELECT 4, 'c', 30 FROM dual UNION ALL SELECT 5, 'd', 40 FROM dual ) SELECT COALESCE(cd, gb, '합계') cd , SUM(v) v FROM (SELECT id, cd, v , CASE WHEN cd IN ('a', 'b') THEN '(a+b)소계' ELSE 'etc' END gb FROM t ) GROUP BY ROLLUP(gb, (id, cd)) HAVING NOT(NVL(gb, 'x') = 'etc' AND GROUPING(cd) = 1) ORDER BY gb NULLS FIRST, id ;