备注:createDate :时间字段
select
sum(case month(createDate) when '1' then 1 else 0 end) as 2020年1月份,
sum(case month(createDate) when '2' then 1 else 0 end) as 2020年2月份,
sum(case month(createDate) when '3' then 1 else 0 end) as 2020年3月份,
sum(case month(createDate) when '4' then 1 else 0 end) as 2020年4月份,
sum(case month(createDate) when '5' then 1 else 0 end) as 2020年5月份,
sum(case month(createDate) when '6' then 1 else 0 end) as 2020年6月份,
sum(case month(createDate) when '7' then 1 else 0 end) as 2020年7月份,
sum(case month(createDate) when '8' then 1 else 0 end) as 2020年8月份,
sum(case month(createDate) when '9' then 1 else 0 end) as 2020年9月份,
sum(case month(createDate) when '10' then 1 else 0 end) as 2020年10月份,
sum(case month(createDate) when '11' then 1 else 0 end) as 2020年11月份,
sum(case month(createDate) when '12' then 1 else 0 end) as 2020年12月份
from 表
where year(createDate)= '2020' ;