注册 登录
编程论坛 ASP技术论坛

asp:查询每个学生的各科成绩,总分,平均分的sql语句

fuyongzhen 发布于 2016-05-23 16:25, 6405 次点击
只有一个score表,字段是:               xjh      name      zuohao         xueke        score
                                        L001     张三        01           语文         65
                                        L002     李四        02           数学         85
                                        L001     张三        01           数学         75
                                        L002     李四        02           语文         55

我想要的结果是:                        xjh      name      zuohao        yuwen         shuxue      zongfen       pjf
                                        L001     张三        01           65            75          140           70
                                        L002     李四        02           55            85          140           70

下面是我的sql语句:
dim rs,sql,sql2,zt,ck,nf,xq,cx,bj,bjmc,info
   
    nf="2016"
    xq="春季学期"
    cx="期中考试"
    bjmc="小学2012级3班"
    set rs=server.CreateObject("Adodb.Recordset")
    sql="select zuohao,name,xjh,"
    sql=sql&"sum(case when xueke='语文' then score else 0 end) as yuwen,"
    sql=sql&"sum(case when xueke='数学' then score else 0 end) as shuxue,"
    sql=sql&"sum(case when xueke='英语' then score else 0 end) as yingyu,"
    sql=sql&"sum(case when xueke='综合' then score else 0 end) as zhonghe,"
    sql=sql&"sum(score) as zongfen,"
    sql=sql&"sum(score)*1.0/4 as pjf"
    sql=sql&" from score where nianfen='"&nf&"' and xueqi='"&xq&"' and cixu='"&cx&"' and bjmc='"&bjmc&"' group by zuohao,name,xjh order by desc zongfen"
    rs.open sql,conn,1,1

提示错误:错误 '80004005' ,/StudentScore.asp,行 92 (注:92行就是:rs.open sql,conn,1,1)

怎么办啊?谢谢大虾
1 回复
#2
hu9jj2016-05-24 08:04
建议先将出错的语句分拆开逐个测试,比如先统计语文的成绩,通过之后再加上数学的成绩,依此类推,这样就容易排查问题。
1