select A,B=(Select sum(B) from tbl where A=x.A and B<=x.B)
from tbl as x

解决方案 »

  1.   

    好思路,但如果是A      B
    a      1
    a      10
    a      3
    a      10要得到结果a      1
    a      11
    a      14
    a      24就不行了请高手赐教  
      

  2.   

    --建一个临时表用自增列
    select IDENTITY(int, 1, 1) as id,* into #tbl from tbl
    select A,B=(Select sum(B) from tbl where A=x.A and id<=x.id)
    from #tbl as x
      

  3.   

    --上面错了 建一个临时表用自增列
    select IDENTITY(int, 1, 1) as id,* into #tbl from tbl
    select A,B=(Select sum(B) from #tbl where A=x.A and id<=x.id)
    from #tbl as x
      

  4.   

    我点错了,应该给WangZWang(阿来) 15分的,怎样能补分给WangZWang(阿来)呢