ASP 数据相加 将一个表中同一个字段里所有数据相加

来源:百度知道 编辑:UC知道 时间:2024/05/23 01:25:08
将一个表中所有的数据相加,
我的表结构是这样:表名TABLE
字段
id product number
1 aaa 50
2 bbb 80
3 aaa 40
4 bbb 20
5 aaa 10
我想把名称为aaa的所有数量读出并打印到网页上。
一定追加高分,定有重谢
是相加然后打一个总数。
最后页面上就是
aaa的数量是numebr(总数)

你到底是要打印还是要相加?

<%
Set Type_rs=conn.execute("select Type from [Type]")
Do while not Type_rs.eof
product = Type_rs("Type_rs")
Set n_rs=conn.execute("select * from TABLE where product='&product&' ORDER BY id desc")
do while not n_rs.eof
a = n_rs("number")+a
n_rs.movenext
loop
n_rs.close
Set n_rs=nothing
response.write product&"的数量是:"&a
Type_rs.movenext
Loop
Type_rs.close
Set Type_rs=nothing
%>