WITH t AS ( SELECT 'A' cd, '202306' ym, 1000 amt FROM dual UNION ALL SELECT 'A', '202206', 880 FROM dual UNION ALL SELECT 'B', '202306', 2000 FROM dual UNION ALL SELECT 'B', '202206', 1900 FROM dual ) SELECT cd , SUM(DECODE(ym, '202306', amt)) "202306" , SUM(DECODE(ym, '202206', amt)) "202206" , ROUND( SUM(DECODE(ym, '202306', amt)) / SUM(DECODE(ym, '202206', amt)) * 100 - 100, 2) rat FROM t WHERE ym IN ('202306', '202206') GROUP BY cd ORDER BY cd ;