1、查询一年中每月数据,某月份数据为空补0
SELECT
sum(case DATE_FORMAT(日期字段,'%m') when '01' then 1 else 0 end) as 一月,
sum(case DATE_FORMAT(日期字段,'%m') when '02' then 1 else 0 end) as 二月,
sum(case DATE_FORMAT(日期字段,'%m') when '03' then 1 else 0 end) as 三月,
sum(case DATE_FORMAT(日期字段,'%m') when '04' then 1 else 0 end) as 四月,
sum(case DATE_FORMAT(日期字段,'%m') when '05' then 1 else 0 end) as 五月,
sum(case DATE_FORMAT(日期字段,'%m') when '06' then 1 else 0 end) as 六月,
sum(case DATE_FORMAT(日期字段,'%m') when '07' then 1 else 0 end) as 七月,
sum(case DATE_FORMAT(日期字段,'%m') when '08' then 1 else 0 end) as 八月,
sum(case DATE_FORMAT(日期字段,'%m') when '09' then 1 else 0 end) as 九月,
sum(case DATE_FORMAT(日期字段,'%m') when '10' then 1 else 0 en