SELECT CASE WHEN GROUP_ID() = 0
THEN ' '||NVL(t.catagory,'소계')
ELSE DECODE(t.catalog,'A','자산','C','자본','D','부채')
END AS catagory
, CASE WHEN GROUP_ID() = 0
THEN SUM(DECODE(t.period_name, '08-Jun', t.amount_krw, 0))
END AS this_term
, CASE WHEN GROUP_ID() = 0
THEN SUM(DECODE(t.period_name, '08-Jun', 0, t.amount_krw))
END AS former_term
FROM klc_footnote_bs t
WHERE t.period_name IN ('08-Jun'
, TO_CHAR(ADD_MONTHS(TO_DATE('08-Jun', 'YY-Mon'), -12), 'YY-Mon'))
GROUP BY t.catalog, ROLLUP(t.catalog, t.catagory)
ORDER BY t.catalog, GROUP_ID() DESC, GROUPING(t.catagory)