select 交易时间=convert(char(10),时间,120),交易金额
    ,累计交易金额=(select sum(交易金额) from 表 where 时间<=a.时间)
from 表 a

解决方案 »

  1.   

    --测试--测试数据
    create table 表(时间 datetime,交易金额 int)
    insert 表 select '2002-01-01',10000
    union all select '2002-01-02',20000
    union all select '2002-02-10',15000
    union all select '2002-03-02',80000
    go--查询
    select 交易时间=convert(char(10),时间,120),交易金额
    ,累计交易金额=(select sum(交易金额) from 表 where 时间<=a.时间)
    from 表 a
    go--删除测试
    drop table 表/*--测试结果
    交易时间       交易金额        累计交易金额      
    ---------- ----------- ----------- 
    2002-01-01 10000       10000
    2002-01-02 20000       30000
    2002-02-10 15000       45000
    2002-03-02 80000       125000(所影响的行数为 4 行)--*/