1) select a.id,sum(b.a)
from table a join table b
on a.id>=b.id
group by a.id
2)select a.id,isnull(a.a+b.a,a.a)
from table a left join table b
on a.id=b.id+1orselect id,isnull(a+(select a from #t where id=(select max(id) from #t where id<a.id)),a)
from #t a

解决方案 »

  1.   

    1、
    select id,a+isnull((select a from 表 where id=aa.id-1),0) from 表 aa2、
    select id,a+isnull((select a from 表 where id<aa.id),0) from 表 aa
      

  2.   

    写反了上面的是22、
    select id,a+isnull((select a from 表 where id=aa.id-1),0) from 表 aa1、
    select id,a+isnull((select a from 表 where id<aa.id),0) from 表 aa
      

  3.   

    改为 select id,a+isnull((select sum(a) from 表 where id<aa.id),0) from 表 aa
      

  4.   

    select id,a+isnull((select a from 表 where id<aa.id),0) from 表 aa
    这个会
    子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
      

  5.   

    哈哈。。 一时手快!望打sum了!
      

  6.   

    1、
    select id,a+isnull((select sum(a) from 表 where id<aa.id),0) from 表 aa2、
    select id,a+isnull((select a from 表 where id=aa.id-1),0) from 表 aa
      

  7.   

    最后的答案应该是:
    1、
    select id,a+isnull((select a from 表 where id<aa.id),0) from 表 aa
    2、
    select id,a+isnull((select top 1 a from 表 where id<aa.id order by id desc),0) from 表 aa
      

  8.   

    select id,a+isnull((select top 1 a from 表 where id<aa.id order by id desc),0) from 表 aa应为你有可能出现:
    id a
    1 10 
    3 13 
    4 14