我有一张如下表:
CREATE TABLE [TBL_test] ([ID] int PRIMARY KEY,[RDate] CHAR(10),[Debtor] int,
[Creditor] int);
insert into [TBL_test] values(1,'2012/10/11',100,0);
**insert into [TBL_test] values(2,'2012/11/02',20,0);**
insert into [TBL_test] values(3,'2012/11/09',0,5);
**insert into [TBL_test] values(4,'2012/11/02',0,10);**
select *,(select sum(t2.Debtor - t2.Creditor) from TBL_test t2 where t2.rdate <=
t1.rdate
order by rdate) as RT
from TBL_test t1
order by rdate
结果
ID RDate Debtor Creditor RT
1 2012/10/11 100 0 100
2 2012/11/02 20 0 110
4 2012/11/02 0 10 110
3 2012/11/09 0 5 105
请建议我该如何解决这个问题