关于分组求和的问题
ACCESS数据库表:
bpname pfname bs yuefen fen1 fen2
张三 李四 3 200704 8 10
张三 李四 1 200704 10 7
张三 李四 1 200704 10 10
张三 李四 2 200704 10 10
赵五 李四 3 200704 8 10
赵五 李四 1 200704 10 7
赵五 李四 1 200704 10 10
赵五 李四 2 200704 10 10
我查询的代码是这样写的:
<%
set rs=server.createobject( "adodb.recordset ")
set rs2=server.createobject( "adodb.recordset ")
str1= "select * from pc_one_all_result where bs=3 "
rs.open str1,conn,1,1
if not rs.eof then
sqlstr= "select bpname,round(((select sum(fen1+fen2+fen3+fen4+fen5)*3 from pc_one_all_result where bs=3 ) "
else
sqlstr= "selct bpname,round(((0 "
end if
rs.close
str2= "select * from pc_one_all_result where bs=2 "
rs.open str2,conn,1,1
if not rs.eof then
sqlstr=sqlstr & "+(select sum(fen1+fen2+fen3+fen4+fen5)*2 from pc_one_all_result where bs=2) "
else sqlstr=sqlstr & "+0 "
end if
rs.close
str3= "select * from pc_one_all_result where bs=1 "
rs.open str3,conn,1,1
if not rs.eof then
sqlstr=sqlstr & "+(select sum(fen1+fen2+fen3+fen4+fen5)*1 from pc_one_all_result where bs=1)) "
else sqlstr=sqlstr & "+0) "
end if
rs.close
sqlstr=sqlstr & "/(select sum(bs) from pc_one_all_result ),2) as fenz from pc_one_all_result GROUP BY bpname ORDER by bpname desc "
rs2.open sqlstr,conn,1,1
if &nb