select A.YY,
sum(decode(A.mm, '01', A.NUM, 0)) as 一月,
sum(decode(A.mm, '02', A.NUM, 0)) as 二月,
sum(decode(A.mm, '03', A.NUM, 0)) as 三月,
sum(decode(A.mm, '04', A.NUM, 0)) as 四月,
sum(decode(A.mm, '05', A.NUM, 0)) as 五月,
sum(decode(A.mm, '06', A.NUM, 0)) as 六月,
sum(decode(A.mm, '07', A.NUM, 0)) as 七月,
sum(decode(A.mm, '08', A.NUM, 0)) as 八月,
sum(decode(A.mm, '09', A.NUM, 0)) as 九月,
sum(decode(A.mm, '10', A.NUM, 0)) as 十月,
sum(decode(A.mm, '11', A.NUM, 0)) as 十一月,
sum(decode(A.mm, '12', A.NUM, 0)) as 十二月code
from (select count(1) num,
substr(to_char(m.optdate, 'yyyyMM'), 0, 4) yy,
substr(to_char(m.optdate, 'yyyyMM'), 5, 2) mm
FROM czrzb M
group by to_char(m.optdate, 'yyyyMM')) A
group by A.YY
order by A.YYdate
如圖:select