日期:2014-05-18  浏览次数:20437 次

月份改变,怎么样使数据列自动递加,谢谢
当月份为1时,为如下结表达式:
select  
sum(aj1)   fsjf,
sum(ad1)   fsdf,
sum(aj1)   ljjf,
sum(ad1)   ljdf    
from     a
如果当月份为2时,为如下表达式:
select  
sum(aj1)+sum(aj2)   fsjf,
sum(ad1)+sum(ad2)   fsdf,
sum(aj1)+sum(aj2)   ljjf,
sum(ad1)+sum(ad2)   ljdf    
from     a
依此类推...谢谢


------解决方案--------------------
--try

select
fsjf=SUM(case 月份 when 1 then aj1 when 2 then aj1+aj2 when ... then ... end)
from a
group by ...

------解决方案--------------------
select sum( (case when month(getdate)> =1 then aj1 else 0 end)+
(case when month(getdate)> =2 then aj2 else 0 end)+
(case when month(getdate)> =3 then aj3 else 0 end))fsjf,