西湖鱼 发表于 2018-10-22 07:56:36

sql按月求和语句

select  
sum(case when rq >='2015-1-1' and rq < '2015-2-1' then sl else 0 end) as '1月份',
  
sum(case when rq >='2015-2-1' and rq < '2015-3-1' then sl else 0 end) as '2月份',
  
sum(case when rq >='2015-3-1' and rq < '2015-4-1' then sl else 0 end) as '3月份'
  
from a2;


页: [1]
查看完整版本: sql按月求和语句