SELECT t.category_code
, CASE WHEN GROUPING(t.category_code) = 0
THEN ' '||t.category_name
ELSE c.attribute2 || DECODE(GROUP_ID(),0,'계',':')
END AS category_name
, CASE WHEN GROUP_ID() = 0
THEN SUM(DECODE(t.period_name,'Dec-99',t.amount_krw,0))
END AS this_term
, CASE WHEN GROUP_ID() = 0
THEN SUM(DECODE(t.period_name,'Dec-99',0,t.amount_krw))
END AS former_term
FROM klc_footnote_other_profit_loss t
, (SELECT 'A' attribute1, '기타이익' attribute2 FROM dual
UNION ALL SELECT 'B', '기타손실' FROM dual
) c
WHERE t.attribute1 = c.attribute1
AND t.period_name IN ('Dec-99'
, TO_CHAR(ADD_MONTHS(TO_DATE('Dec-99','Mon-YY'),-12),'Mon-YY') )
GROUP BY t.attribute1, c.attribute2
, ROLLUP(t.attribute1, (t.category_code, t.category_name))
ORDER BY t.attribute1, GROUP_ID() DESC, t.category_code