首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

学生成绩按总分排序后,怎样显示名次解决办法

2012-03-11 
学生成绩按总分排序后,怎样显示名次我做了个学生成绩统计表,按总分做降序排序后,无法显示名次,相关ASP代码

学生成绩按总分排序后,怎样显示名次
我做了个学生成绩统计表,按总分做降序排序后,无法显示名次,相关ASP代码如下:
  </table>
  <%   grade=request.querystring( "grade ")
  banji=request.querystring( "class ")
dim   rs              
dim   sql

set   rs=server.createobject( "adodb.recordset ")
sql= "select(select   count(*)from   scores   where     language> =a.language   and   grade= "&grade& "   and   class= "&banji& "     )   as   mingci1,(select   count(*)from   scores   where   mathe> =a.mathe   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci2,(select   count(*)from   scores   where   english> =a.english   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci3,(select   count(*)from   scores   where   physics> =a.physics   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci5,(select   count(*)from   scores   where   chemical> =a.chemical   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci6,(select   count(*)from   scores   where   biological> =a.biological   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci7,(select   count(*)from   scores   where   politics> =a.politics   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci8,(select   count(*)from   scores   where   history> =a.history   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci9,(select   count(*)from   scores   where   geography> =a.geography   and   grade= "&grade& "   and   class= "&banji& ")   as   mingci10,(select   count(*)   from   scores   where       language+mathe+english+physics+chemical+biological+politics+history+geography> =a.language+a.mathe+a.english+a.physics+a.chemical+a.biological+a.politics+a.history+a.geography     and   grade= "&grade& "   and   class= "&banji& ")   as   mingci4,*   from   scores   a   where   grade= "&grade& "   and   class= "&banji&   " "

sql= "select   *   from   scores   where       grade= "&grade& "   and   class= "&banji& "       order   by   zf   desc "   '按总分降序排列

rs.open   sql,conn,1,3


if   rs.eof   then
response.write " <font   color=red> 对不起,暂时没有相关成绩 </font> "
end   if
do   while   not   rs.eof


%>

                                     


                        <table   width= "750 "   border= "1 "   cellspacing= "0 "   cellpadding= "0 "   align= "center "   height= "22 "   style= "border-top-width:0px ">


                            <tr>  
                                <td   width= "57 "   height= "17 ">  
                                    <div   align= "center "> <%=rs( "testnumber ")%> </div>   '学号
                                </td>
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "name ")%> </div> '姓名
                                </td>
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "language ")%> </div> '语文
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "mathe ")%> </div> '数学
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "english ")%> </div> '英语
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "physics ")%> </div> '物理
                                </td>
                               


                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "chemical ")%> </div> '化学
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "biological ")%> </div> '生物
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "politics ")%> </div> '政治
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "history ")%> </div> '历史
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "geography ")%> </div> '地理  
                                </td>
                               
                                <td   width= "57 ">  
                                    <div   align= "center "> <%=rs( "zf ")%> </div> '总分


                                </td>
<td   width= "38 ">  
                                    <div   align= "center "> <%=rs( "mingci4 ")   %> </div> '名次
                                </td>
                             
                            </tr>
                        </table>
                        <%
rs.movenext
loop
rs.close
%>
如果把   (sql= "select   *   from   scores   where       grade= "&grade& "   and   class= "&banji& "       order   by   zf   desc "   '按总分降序排列)   这句删除,则能显示名次,但这时顺序是乱的,如果不删除这句,测试浏览时则报错,报错提示为:错误类型:
ADODB.Recordset   (0x800A0CC1)
在对应所需名称或序数的集合中,未找到项目。
/test/main.asp,   第   417   行

第417行是: <div   align= "center "> <%=rs( "mingci4 ")   %> </div>
其实报错的原因我知道,因为mingci4并不是数据表字段,数据表(scores)有15个字段,分别是:id,testnumber,name,language,mathe,english,physics,chemical,biological,politics,history,geography,zf   程序找不到mingci4字段,故报错了,但是我在数据表里加上mingci4字段,虽然不报错,名次一栏则显示为空,我这个数据表较特殊,因为几个班的成绩都在这表里,我要的是既能按总分排序,又能显示名次,弄了很久,都不行,晕了!望各位大侠指导,谢!!!!!!!(最好给出相关代码),急!


[解决办法]
创建一个视图就好了嘛,用得着那么多的代码吗?create view 读取试图然后order by。。。。。。。。。。
[解决办法]
一看那么多代码我脑袋就大~!~
[解决办法]
朋友,这代码也太长了吧,

热点排行