mysql按月統計

select
sum(case month(bau_cos_create_time) when ‘01’ then ROUND(bau_actul_fee) else 0 end) as 一月,
sum(case month(bau_cos_create_time) when ‘02’ then ROUND(bau_actul_fee) else 0 end) as 二月,
sum(case month(bau_cos_create_time) when ‘03’ then ROUND(bau_actul_fee) else 0 end) as 三月,
sum(case month(bau_cos_create_time) when ‘04’ then ROUND(bau_actul_fee) else 0 end) as 四月,
sum(case month(bau_cos_create_time) when ‘05’ then ROUND(bau_actul_fee) else 0 end) as 五月,
sum(case month(bau_cos_create_time) when ‘06’ then ROUND(bau_actul_fee) else 0 end) as 六月,
sum(case month(bau_cos_create_time) when ‘07’ then ROUND(bau_actul_fee) else 0 end) as 七月,
sum(case month(bau_cos_create_time) when ‘08’ then ROUND(bau_actul_fee) else 0 end) as 八月,
sum(case month(bau_cos_create_time) when ‘09’ then ROUND(bau_actul_fee) else 0 end) as 九月,
sum(case month(bau_cos_create_time) when ‘10’ then ROUND(bau_actul_fee) else 0 end) as 十月,
sum(case month(bau_cos_create_time) when ‘11’ then ROUND(bau_actul_fee) else 0 end) as 十一月,
sum(case month(bau_cos_create_time) when ‘12’ then ROUND(bau_actul_fee) else 0 end) as 十二月
from bau_consume

更多技术文章请关注公众号:架构师Plus,
扫码添加
mysql按月統計_第1张图片

你可能感兴趣的:(数据库)