table的结构和数据
Time Money
1 10
2 15
3 23
4 22
5 100
6 78
查询结果:
Time Money Total
1 10 10
2 15 25
3 23 48
4 22 70
5 100 170
6 78 248
注:Total=上一次Total+本次Money;
例如:Time1的Total=10
      Time2的Total=10+15=25(Time1的Total+ Time2的Money)
      Time3的Total=25+23=48
谢谢了,

解决方案 »

  1.   

    select a.Time,a.Money,total=(select sum(Money) from @t where Time<=a.Time) from @t a
      

  2.   

    declare @t table(Time int,Money int)
    insert into @t select 1,10
    insert into @t select 2,15
    insert into @t select 3,23
    insert into @t select 4,22
    insert into @t select 5,100
    insert into @t select 6,78select a.Time,a.Money,total=(select sum(Money) from @t where Time<=a.Time) from @t a/*
    Time        Money       total       
    ----------- ----------- ----------- 
    1           10          10
    2           15          25
    3           23          48
    4           22          70
    5           100         170
    6           78          248
    */