表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
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
是 SQL SERVER
from tablename a
order by name
用一个循环加计数器可以很轻松解决。
table1.first;
sum:=0;
while not table1.eof do
begin
sum := sum + table1['value'];
next;
end;
然后 修改一下楼上的
select a.name,a.value,(select sum(value) from tablename where id <=a.id) as total
from tablename a order by name
厉害厉害 好使 谢谢