表table格式如下
name value
a    10
b    15
c    20
d    30统计成如下形式 
 (注:total为 前面value 之和  b  的total = a.value+b.value,
 c.total=a.value+b.value+c.value  或c.total=b.total+c.value name value total
a    10    10
b    15    25 
c    20    45
d    30    75

解决方案 »

  1.   

    同上,如果是SQL Server,可以动用游标嘛
      

  2.   

    可以详细一些吗?
    是    SQL SERVER
      

  3.   

    SQL Server,不用游标select name,value,(select sum(value) from tablename where name <=a.name) as total
    from tablename a
    order by name
      

  4.   

    一条SQL语句实现不了,即便实现可读性和效率也很差。
    用一个循环加计数器可以很轻松解决。
    table1.first;
    sum:=0;
    while not table1.eof do
    begin
      sum := sum + table1['value'];
      next;
    end;
      

  5.   

    按name排序,不可以的话就drop一个自增的id把name换成id
    然后 修改一下楼上的
    select a.name,a.value,(select sum(value) from tablename where id <=a.id) as total
    from tablename a order by name
      

  6.   

    to  Rewiah(乘长风) :
      厉害厉害   好使 谢谢