表 A 结构如下
ID    B
1     2.1
2     1.2
3     3.5要求查询结果如下
id    sum
1     2.1
2     3.3
3     6.8 
语句怎么写?   我这没有SQLServer,
我是个新手,没分了。

解决方案 »

  1.   

    select id ,   [sum]=(select sum(b) from ta where id!>a.id)
    from ta a
      

  2.   

    declare @ta table(ID int,    B decimal(15,2))
    insert @ta select 1,     2.1
    union all select  2,     1.2
    union all select  3,     3.5select id,
    [sum]=(select sum(b)from @ta where id!>a.id)
     from @ta a(3 行受影响)
    id          sum
    ----------- ---------------------------------------
    1           2.10
    2           3.30
    3           6.80(3 行受影响)