关于求和显示的问题,高手帮忙。送上100分

97jr 2003-09-29 01:47:46
我想从数据库表stu中查询一些记录,这些记录查出来之后要在网页上显示结果如下:
name score
张三 80
张三 90
张三 60
小计 230
李四 60
李四 70
李四 80
小计 210
合计 440

请问该如何写查询语句?上边的格式如何在网页上显示。
谢谢
...全文
37 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
97jr 2003-10-10
  • 打赏
  • 举报
回复
解决了
homeyang 2003-09-29
  • 打赏
  • 举报
回复
sql="select distinct name from table"
rs.open sql,conn,1,3
do while not rs.eof
set rs1=server.createobject("adodb.recordset")
sql="select sum(sorce) as a from table where stu_id=" & rs("stu_id")
rs1.open sql,conn,1,3
response.write rs1("a") & "<br>"
rs1.close
rs.movenext
loop
rs.close
homeyang 2003-09-29
  • 打赏
  • 举报
回复
你可以用distinct就行啦
homeyang 2003-09-29
  • 打赏
  • 举报
回复
判断name不就行啦
97jr 2003-09-29
  • 打赏
  • 举报
回复
李文写的程序没有写出每个学生的小计成绩,现在学生的个数不固定,每个学生的记录条数也不固定。我该怎么才能准确得出每个学生有多少条记录,准确把每个学生分开。
homeyang 2003-09-29
  • 打赏
  • 举报
回复
select sum(sorce1) as a,sum(sorce2) as b from table where 条件

取的时候用
rs("a")和rs("b")就行啦
avonqin 2003-09-29
  • 打赏
  • 举报
回复
楼上,人家还要导出所有学生姓名和分数呢,你那样只能打印出某位学生的总分呀
Brookes 2003-09-29
  • 打赏
  • 举报
回复
可以参考:
http://www.microsoft.com/china/msdn/technic/develop/ado.asp
Brookes 2003-09-29
  • 打赏
  • 举报
回复
使用compute
chinanetspy 2003-09-29
  • 打赏
  • 举报
回复
select sum(score) as totalnum where stuid="&stuid


这个已经可以解决你的问题了
avonqin 2003-09-29
  • 打赏
  • 举报
回复
方法二:

<%
…………
Set RS=server.CreateObject("ADODB.RecordSet")
sql="select * from stu "
rs.open sql,conn,1,1
TotalScore=0
%>
<table width=300>
<tr><td align=center>name</td><td align=center>score</td></tr>
<% for iCount=1 to RS.RecordCount
TotalScore=TotalScore+Trim(RS("Score"))
response.write "<tr><td align=center>"&Trim(RS("name"))&"</td><td align=center>"&Trim(RS("Score"))&"</td></tr>"
next
%>
<tr><td align=right colspan=2>合计:<%=TotalScore%></td></tr>
</table>
angelheavens 2003-09-29
  • 打赏
  • 举报
回复
CSDN就这点不好:打错了,本人不能修改帖子


举例说明,假设
sql=select sum(score) as totalnum,stuname,sex[,...fieldname] where stuid="&stuid
set rs=conn.execute(sql)
if rs.eof and rs.bof then
else
response.write trim(rs("totalnum"))&" "&rs("sex")...
end if
angelheavens 2003-09-29
  • 打赏
  • 举报
回复
举例说明,假设
sql=select select sum(score) as totalnum,stuname,sex[,...fieldname] where stuid="&stuid
set rs=conn.execute(sql)
if rs.eof and rs.bof then
else
response.write trim(rs("totalnum"))&" "&rs("sex")...
end if
lovehwq21 2003-09-29
  • 打赏
  • 举报
回复
如果是多字段的,象你这种方法最好用存储过程做
dsfdsl 2003-09-29
  • 打赏
  • 举报
回复
select sum(score) as totalnum where stuid="&stuid
这个正确呀
你用<table>输出totalnum字段就ok了
97jr 2003-09-29
  • 打赏
  • 举报
回复
不只是一个sum字段,还有其他的字段呢。我用这种方法加上别的字段就不行了。
另外还有在网页上如何显示上面的格式呢?
angelheavens 2003-09-29
  • 打赏
  • 举报
回复
给分
angelheavens 2003-09-29
  • 打赏
  • 举报
回复
sorry:
select sum(score) as totalnum where stuid="&stuid
angelheavens 2003-09-29
  • 打赏
  • 举报
回复
假设是查寻某学生的各科总成绩:

select sum(name) as totalnum where stuid="&stuid

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧