case -------------如果
when sex='1' then '男' -------------sex='1',则返回值'男'
when sex='2' then '女' -------------sex='2',则返回值'女'
else 0 -------------其他的返回'其他’
end -------------结束
from sys_user --------整体理解: 在sys_user表中如果sex='1',则返回值'男'如果sex='2',则返回值'女' 否则返回'其他’
-----------------------------------------------------------------------------------------------------------------------------------------------
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
where year(a.GOODSDATE)='2018'; 注:--year(now());--为获取当前日期
-----------------------------------------------------------------------------------------------------------