1. 程式人生 > >MYSQL語句一年內12個月各月某列引數統計顯示

MYSQL語句一年內12個月各月某列引數統計顯示

select   
sum(case month(a.GOODSDATE) when '1' then a.GOODSACTUALPRICE else 0 end) as 一月份,  
sum(case month(a.GOODSDATE) when '2' then a.GOODSACTUALPRICE else 0 end) as 二月份,  
sum(case month(a.GOODSDATE) when '3' then a.GOODSACTUALPRICE else 0 end) as 三月份,  
sum(case month(a.GOODSDATE) when '4' then a.GOODSACTUALPRICE else 0 end) as 四月份,  
sum(case month(a.GOODSDATE) when '5' then a.GOODSACTUALPRICE else 0 end) as 五月份,  
sum(case month(a.GOODSDATE) when '6' then a.GOODSACTUALPRICE else 0 end) as 六月份,  
sum(case month(a.GOODSDATE) when '7' then a.GOODSACTUALPRICE else 0 end) as 七月份,  
sum(case month(a.GOODSDATE) when '8' then a.GOODSACTUALPRICE else 0 end) as 八月份,  
sum(case month(a.GOODSDATE) when '9' then a.GOODSACTUALPRICE else 0 end) as 九月份,  
sum(case month(a.GOODSDATE) when '10' then a.GOODSACTUALPRICE else 0 end) as 十月份,  
sum(case month(a.GOODSDATE) when '11' then a.GOODSACTUALPRICE else 0 end) as 十一月份,  
sum(case month(a.GOODSDATE) when '12' then a.GOODSACTUALPRICE else 0 end) as 十二月份
from sale a