asp,sql高手请指教

memewa1 2009-07-30 09:27:26
有两个表,A表,B表,里面的内容如下:
A:北京、上海、四川。。。。。。。
B:1.张三、北京、600分
2.李四、北京、577分
3.王五、上海、610分
。。。。。。。。。。。。。。。。。。

要实现以下效果以表格的形式,

北京 总分:(所有隶属北京学生的分数相加)
张三 600分
李四 577分
。。。。。。。。。。。。
上海 总分(所有隶属北京学生的分数相加)
王五 610分
。。。。。。。。。。。。。。。
四川
。。。。。。。。。。。。。。。。。。
...全文
87 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dogfish 2009-07-31
  • 打赏
  • 举报
回复
set rs = CreateObject("ADODB.Recordset")
rs.Open "select * from table order by 地区, 成绩 desc", conn
response.write "<table>"
area = ""
area1 = ""
do while not rs.EOF
if area <> rs("地区") then
area = rs("地区")
area1 = area
else
area1 = ""
end if
if area1 <> "" then
response.write "<tr>"
response.write "<td>" & area1 & "</td>"
response.write "<td></td>"
response.write "<td>总分</td>"
response.write "</tr>"
end if
response.write "<tr>"
response.write "<td></td>"
response.write "<td>" & rs("姓名") & "</td>"
response.write "<td>" & rs("总分") & "</td>"
response.write "</tr>"
rs.movenext
wend
response.write "</table>"
王者coco 2009-07-31
  • 打赏
  • 举报
回复
up
野人丶嘎嘎 2009-07-31
  • 打赏
  • 举报
回复
楼上所言极是
hongmaohouzi 2009-07-31
  • 打赏
  • 举报
回复
set rs = CreateObject("ADODB.Recordset")
rs.Open "select * from table order by 地区, 成绩 desc", conn
response.write "<table>"
area = ""
area1 = ""
do while not rs.EOF
if area <> rs("地区") then
area = rs("地区")
area1 = area
else
area1 = ""
end if
if area1 <> "" then
response.write "<tr>"
response.write "<td>" & area1 & "</td>"
response.write "<td></td>"
response.write "<td>总分</td>"
response.write "</tr>"
end if
response.write "<tr>"
response.write "<td></td>"
response.write "<td>" & rs("姓名") & "</td>"
response.write "<td>" & rs("总分") & "</td>"
response.write "</tr>"
rs.movenext
wend
response.write "</table>"
lzp4881 2009-07-31
  • 打赏
  • 举报
回复
请参考这个帖子,你的问题跟他差不多
http://topic.csdn.net/u/20080610/17/789b65a4-064e-4c3e-952a-fd59b3e65ee9.html
hookee 2009-07-30
  • 打赏
  • 举报
回复
access的话
oConn.Provider = "MSDataShape"
oConn.ConnectionString = "一般连接串"
hookee 2009-07-30
  • 打赏
  • 举报
回复
用DataShap,很简单
以下是sql server的


<%
Set oConn = CreateObject("ADODB.Connection")
sConn = "Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=SENSTAR;User ID=sa;Password=sa;"
oConn.Open sConn
sql = "SHAPE{SELECT place FROM A}" &_
"APPEND({SELECT name, place, score FROM B} AS STU " &_
"RELATE place TO place)," &_
"({SELECT place, SUM(score) AS ttl FROM B GROUP BY place} AS SM " &_
"RELATE place TO place)"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sql, oConn
Do While Not oRS.EOF
Set oRS2 = oRS("SM").Value
Response.Write "<BR>"
Response.Write oRS("place") & "   " & oRS2("ttl") & "<br>"
Set oRS1 = oRS("STU").Value
DO While Not oRS1.EOF
Response.Write oRS1("name") & "     " &_
oRS1("place") & "     " &_
oRS1("score") & "     " & "<BR>"
oRS1.MoveNext
Loop
oRS.MoveNext
Loop
oRS.close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
%>
  • 打赏
  • 举报
回复
http://www.myziy.com/show.php?contentid=151
看看这个例子程序
北京不不 2009-07-30
  • 打赏
  • 举报
回复
用ASP去分吧
先排好序select * from table order by adrs (假设adrs就是地区字段)
记录上条记录的地区名称,如果名称不一样,就输出地区名称,再显示记录
dim
adrs=""
do while not rs.eof
if rs("adrs")<>adrs then
response.write rs("adrs") '如果地区和上条记录地区不同,显示地区名
end if
response.write rs("姓名")&rs("分数")&"<br>" '输出记录
adrs=rs("adrs")
rs.movenext()
loop
  • 打赏
  • 举报
回复
算总分这个不好用SQL算
不过可以利用程序实现
好网管网吧留言本(ASP程序) 更新说明: 1、增加外部提交检测代码,防止外部提交(如有更好建议,分享); 2、增加过滤特殊字符问题,防止SQL注入。 程序说明: 1、开发环境:DreamWeaver CS3 + Asp + ACCESS,在XP SP2 + IIS 5.1版本下测试通过。 2、程序功能:发布留言,查看留言,查找留言,验证码功能(有效防止垃圾留言),IP地址记录,对留言进行回复处理,删除操作,后台修改管理员密码(密码MD5加密,不可破解),数据库防止下载。 3、其他说明:程序简单实用,操作简单,美观大方。 4、密码已经过MD5加密处理!如忘记密码,将数据库下载至本地,修改“G_man”表“密码”列内容为【7a57a5a743894a0e】,则新密码为【admin】。 5、使用说明: 本地:下载本程序解压后,运行IIS,设置好访问路径即可。 如:http://localhost/ 网络:下载本程序解压后,直接将文件夹内文件上传至空间即可(最好新建文件夹,防止覆盖网站原文件)。 地址:http://www.你的域名.com/程序所在文件夹名/ 6、程序默认用户名:admin 密码:admin 后台管理地址:a_login.asp (程序底部gxjss链接为后台管理地址) 强烈建议修改数据库文件名,并修改数据库链接文件; 修改 Connections 下 gconn 文件(可用记事本打开),修改数据库名 Server.MapPath("data/#data.asp") 中 #data.asp 为你自己的数据库文件名。 7、保留阿希正传及其链接,谢谢! 8、作者水平有限,程序如有错误或漏洞,高手指教!感激不尽!

28,409

社区成员

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

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