回 帖 发 新 帖 刷新版面

主题:[讨论]如何能有效、快速的对数据表进行分类汇总,并保存于另一数据表中?

数据表的结构为:
name  subject  question  answer1 answer2
张三  工程       1       ABC     Text

要求对name,subject,question相同的记录中的answer1字段中选择A、B、C的分别汇总;同时要求将answer2中的文本加起来!

回复列表 (共2个回复)

沙发

快速不是很求效率。

板凳


Server.ScriptTimeout = 600
set rs1=server.createobject("adodb.recordset")
rs1.open "select * from answer",conn,1,1
rs1.movefirst
conn.Execute("delete from Totle") 
for i=1 to rs1.recordcount
    AClassName=rs1("classname")
    ASubject=rs1("subject")
    set rs2=server.createobject("adodb.recordset")
    sql="select * from object where 名称='"&AClassName&"'"
    rs2.open sql,conn,1,1
    PNumber=rs2("人数")
    AQuestion=rs1("question")
    set rs=server.createobject("adodb.recordset")
    sql="select * from Totle where classname='"&Aclassname&"' and subject='"&Asubject&"' and question="&Aquestion
    rs.open sql,conn,1,3
    if rs.recordcount=0 then
        rs.addnew
        rs("classname")=aClassname
        rs("subject")=asubject
        rs("TeacherName")=rs2(asubject)
        rs("question")=aquestion
        rs("answernumber")=PNumber
        if instr(rs1("answer1"),"A")>0 then rs("answerA")=1
        if instr(rs1("answer1"),"B")>0 then rs("answerB")=1
        if instr(rs1("answer1"),"C")>0 then rs("answerC")=1
        if instr(rs1("answer1"),"D")>0 then rs("answerD")=1
        if len(rs1("answer2"))>0 then rs("textanswer")=trim(rs1("answer2"))
        rs.update
        rs.close
    else
        if instr(rs1("answer1"),"A")>0 then rs("answerA")=rs("answerA")+1
        if instr(rs1("answer1"),"B")>0 then rs("answerB")=rs("answerB")+1
        if instr(rs1("answer1"),"C")>0 then rs("answerC")=rs("answerC")+1
        if instr(rs1("answer1"),"D")>0 then rs("answerD")=rs("answerD")+1
        if len(rs1("answer2"))>0 then rs("textanswer")=rs("textanswer")&","&trim(rs1("answer2"))
        rs.update
        rs.close
    end if
    rs2.close
    rs1.movenext
next
rs1.close
set rs=server.createobject("adodb.recordset")
rs.open "select * from Totle",conn,1,3
rs.movefirst
for i=1 to rs.recordcount
    rs("blanswerA")=FormatNumber(rs("answerA")/rs("answernumber"),4)
    rs("blanswerB")=FormatNumber(rs("answerB")/rs("answernumber"),4)
    rs("blanswerC")=FormatNumber(rs("answerC")/rs("answernumber"),4)
    rs("blanswerD")=FormatNumber(rs("answerD")/rs("answernumber"),4)
    rs.update
    rs.movenext
next
response.Redirect "analysis.asp?action=end"

就是这个代码.望大家给出祥细建议.

我来回复

您尚未登录,请登录后再回复。点此登录或注册