效果图:
select
sum(case month(createTime) when '' then 1 else 0 end) as 一月份,
sum(case month(createTime) when '' then 1 else 0 end) as 二月份,
sum(case month(createTime) when '' then 1 else 0 end) as 三月份,
sum(case month(createTime) when '' then 1 else 0 end) as 四月份,
sum(case month(createTime) when '' then 1 else 0 end) as 五月份,
sum(case month(createTime) when '' then 1 else 0 end) as 六月份,
sum(case month(createTime) when '' then 1 else 0 end) as 七月份,
sum(case month(createTime) when '' then 1 else 0 end) as 八月份,
sum(case month(createTime) when '' then 1 else 0 end) as 九月份,
sum(case month(createTime) when '' then 1 else 0 end) as 十月份,
sum(case month(createTime) when '' then 1 else 0 end) as 十一月份,
sum(case month(createTime) when '' then 1 else 0 end) as 十二月份,
year(createTime) as year
from fire_disaster
where year(createTime) in('','','','') group by year;
参考地址: https://blog.csdn.net/w3chhhhhh/article/details/54097890