select
y , sum(case when m =1 then 1 else 0 end ) as c1
,sum(case when m =2 then 1 else 0 end ) as c2
...
,sum(case when m =12 then 1 else 0 end ) as c12
from (
select
EXTRACT(year from s_date) as y
, EXTRACT(month from s_date) as m
from exam
) group by y
你试试,这个有一个限制,就是s_date必须是同一年的数据,如果跨年了,你就自己加条件吧。