每个月的数据都是累计值
我需要用4月A机构累计值a - 3月A机构累计值b 求得4月A机构本期值
表如下
statdate comid a b 2011430 11000000 700000.00 800000.00
2011430 11010100 600000.00 550000.00
...
2011331 11000000 750000.00 700000.00
2011331 11010100 600000.00 700000.00
目前处理方法--4月与3月累计做差求4月本期
insert into ta
select '20110429',t1.comid, a1.a-a2.a as a,t1.b-t2.b as b from ta t1,ta t2
where t1.comid=t2.comid
and
t1.statdate='20110430' and t2.statdate='20110331'--删除4月累计值
delete from ta where statdate statdate='20110430'--更新日期
update
ta
set statdate='20110430'
where statdate='20110429'
然后5月的时候还要把5月累计减去前4月加起来再处理
请问有什么好的方法吗,希望有代码~
我需要用4月A机构累计值a - 3月A机构累计值b 求得4月A机构本期值
表如下
statdate comid a b 2011430 11000000 700000.00 800000.00
2011430 11010100 600000.00 550000.00
...
2011331 11000000 750000.00 700000.00
2011331 11010100 600000.00 700000.00
目前处理方法--4月与3月累计做差求4月本期
insert into ta
select '20110429',t1.comid, a1.a-a2.a as a,t1.b-t2.b as b from ta t1,ta t2
where t1.comid=t2.comid
and
t1.statdate='20110430' and t2.statdate='20110331'--删除4月累计值
delete from ta where statdate statdate='20110430'--更新日期
update
ta
set statdate='20110430'
where statdate='20110429'
然后5月的时候还要把5月累计减去前4月加起来再处理
请问有什么好的方法吗,希望有代码~
多谢 可是我有2年的数据都是累计 一个一个做差太麻烦了
还有许多类似的数据 。。存储过程更方便吧 呵呵