首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • sql题目 [已结贴,结贴人:xuantian868]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:24:39 楼主
    学生表Student字段有stuNo,stuName,stuAge分别代表学号,姓名,年龄
    科目表Score字段有sNo,sName分别代表科目编号,科目名称
    成绩表Result 字段有stuNo,sNo,result分别代表学号,科目编号,成绩
    1。找出参加科目名称是‘数学’的学号和学生姓名
    2。找出参加考试超过5次的学生的学号和学生姓名
    3。找出参加全部科目考试的学生的学号和姓名
    30  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:26:511楼 得分:0
    送分啊.. 先顶接分..
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:29:572楼 得分:3
    select student.* from student inner join [result] on student.strno=[result].stuno inner join score on [result].sno=score.sno where score.sname='数学'
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:34:183楼 得分:0
    2) having  子句
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:36:034楼 得分:3
    select student.stuno,student.strname from student inner join result on student.stuno=score.stuno group by student.stuno,student.strname  having count(result.sno)>5
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:38:005楼 得分:2
    select a.stuNo,stuName
    from Student as a
    inner join
    Result as b
    on a.stuNo = b.stuNo
    inner join
    Score as c
    on b.sNo = c.sNo
    where c.sName = '数学'
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:41:096楼 得分:2
    1)select stuNo,stuName
    from Student
    left join Result on Student.stuNo=Result.stuNo
    left join Score on Score.sNo=Result.sNo
    where Score.sName='shuxue'
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:42:127楼 得分:2
    select student.stuno,student.strname from student inner join result on student.stuno=score.stuno  group by student.stuno,student.strname having count(result.sno)=count(score)
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:45:358楼 得分:2
    select student.stuno,student.stuname from student inner join result on student.stuno=result.stuno  group by student.stuno,student.stuname having count(result.sno)=(select count(*) from score)
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 10:46:179楼 得分:0
    第一个问题能不能用嵌套语句实现不用join,谢谢
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 11:21:4110楼 得分:3
    SELECT a.* FROM student a  WHERE a.stuNo IN (SELECT b.stuNo FROM Result b WHERE B.SNO=(SELECT c.SNO FROM Score c WHERE c.SNAME='数学'))
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • ojuju10
    • 等级:
    发表于:2008-04-28 11:35:3411楼 得分:7
    SQL code
    --1 select * from student where stuno in (select stuno from score a,result b where a.sno=b.sno and a.sname='数学') --2 select * from student where sno in (select sno from result group by sno,stuno having count(1)>5) --3 select * from student select student.stuno,student.stuname from student inner join result on student.stuno=result.stuno group by student.stuno,student.stuname having count(result.sno)=(select count(*) from score)
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 12:13:5912楼 得分:6
    SQL code
    1. select stuNo,stuName from Student where stuNo in(select distinct stuNo from result where sNO =(select sNO from Score where sName='数学')) 2. select stuNO,stuName from student inner join(select 学号,count( 科目编号) from result group by 学号 having count( 科目名称)>5)a on a.学号= student.stuNO 3. select stuNO,stuName from student where not exists(select 1 from Score where not exists(select 1 from Result where Result.SNo=Score.Sno and Result.Sno=Student.SNO))
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 12:31:4213楼 得分:0
    ss
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 13:22:0714楼 得分:0
    学习了
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-28 23:39:2415楼 得分:0
    不为了分,只是为了交流下。跟各位兄弟学了不少东东。如下是我的实现:

    1:
    select distinct st.stuNo,st.stuName from Student st inner join Result r on st.stuNo = r.stuNo  inner join Score sc on sc.sNo = r.sNo and sc.sName='高数'

    2:
    select stuNo,stuName
    from Student
    where stuNo in
    (
    select stuNo from Result r group by stuNo having count(stuNo)>5
    )

    3:
    select distinct st.stuNo,st.stuName from Student st inner join Result r on st.stuNo = r.stuNo and r.stuNo in
    (
    select r1.stuNo from Result r1 group by r1.stuNo having count(*) = (select count(*) as scNum from Score )
    )
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved