ASP 记录集筛选重复记录,同一ID号只显示一条并求和!
ASP记录集筛选重复记录,同一ID号只显示一条并求和!如:数据表product有4条记录id,name,num3aa105bb103aa75bb7执行操作后数据表prod...
ASP 记录集筛选重复记录,同一ID号只显示一条并求和!
如:数据表product有4条记录
id,name,num
3 aa 10
5 bb 10
3 aa 7
5 bb 7
执行操作后数据表product只要2条记录,num字段显示上表同一ID的和
id,name,num
3 aa 17
5 bb 17
提醒一下:要删除product表中的重复记录只剩下执行后的记录!谢谢~~ 展开
如:数据表product有4条记录
id,name,num
3 aa 10
5 bb 10
3 aa 7
5 bb 7
执行操作后数据表product只要2条记录,num字段显示上表同一ID的和
id,name,num
3 aa 17
5 bb 17
提醒一下:要删除product表中的重复记录只剩下执行后的记录!谢谢~~ 展开
展开全部
set Rs=server.create("adodb.recordset")
Rs.open "select id,max(name) as name,sum(num) as num from product group by id",conn,1,3
if not Rs.eof then
response.write "id,name,num<br />"
do while not Rs.eof
response.write Rs("id")&","&Rs(name)&","&Rs("num")&"<br />"
set Rss=server.create("adodb.recordset")
Rss.open "select * from product where id='"&Rs("id")&"'",conn,1,3
if not Rss.eof then
for i=1 to Rss.recordcount
if i>1 then
Rss.delete
Rss.update
end if
Rss.movenetx
if Rss.eof then exit for
next
end if
Rss.close
set Rss=nothing
loop
end if
Rs.close
set Rs=nothing
Rs.open "select id,max(name) as name,sum(num) as num from product group by id",conn,1,3
if not Rs.eof then
response.write "id,name,num<br />"
do while not Rs.eof
response.write Rs("id")&","&Rs(name)&","&Rs("num")&"<br />"
set Rss=server.create("adodb.recordset")
Rss.open "select * from product where id='"&Rs("id")&"'",conn,1,3
if not Rss.eof then
for i=1 to Rss.recordcount
if i>1 then
Rss.delete
Rss.update
end if
Rss.movenetx
if Rss.eof then exit for
next
end if
Rss.close
set Rss=nothing
loop
end if
Rs.close
set Rs=nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询