4实验四复杂查询.doc

上传人:李司机 文档编号:1163625 上传时间:2022-07-11 格式:DOC 页数:4 大小:379.50KB
返回 下载 相关 举报
4实验四复杂查询.doc_第1页
第1页 / 共4页
4实验四复杂查询.doc_第2页
第2页 / 共4页
4实验四复杂查询.doc_第3页
第3页 / 共4页
4实验四复杂查询.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《4实验四复杂查询.doc》由会员分享,可在线阅读,更多相关《4实验四复杂查询.doc(4页珍藏版)》请在三一办公上搜索。

1、-实验四复杂查询一、实验目的 掌握两个表以上的连接查询的应用,包括嵌套查询。二、实验容 1查询比林红年纪大的男学生信息。select*fromStudentwhereSe*=男andYEAR(Birth)-(selectYEAR(Birth)fromStudentwhereSname=林红)02检索所有学生的选课信息,包括*、课号、课程名、成绩。selectSC.Sno,Sname,Se*,Classno,ame,GradefromStudents,SC,Coursecwheres.Sno=SC.SnoandSC.o=c.o3查询已选课学生的*、课程名、成绩。selectSC.Sno,Snam

2、e,ame,GradefromStudents,coursec,SCwheres.sno=SC.snoandc.o=SC.o4查询选修了C语言程序设计的学生的*和。selectsc.Sno,SnamefromStudents,coursec,scwherec.ame=C语言程序设计ands.Sno=sc.Snoandsc.o=c.o5查询与虹在同一个班级的学生*、家庭住址。a.用子查询 selectSno,Sname,Home_addrfromStudentwhereClassno=051andSname!=虹b.用连接查询 selectSno,Sname,Home_addrfromStude

3、ntwhereClassno=(selectClassnofromStudentwhereSname=虹)andSname!=虹6查询其他班级中比051班所有学生年龄大的学生的*、。selectSno,SnamefromStudentwhereClassno051andBirth(selectMA*(Grade)fromSCwhereo=002)orderbyGradedesc11检索选修3门以上课程的学生的*、总成绩不统计不及格的课程,并要求按总成绩的降序排列出来。selectSno,sum(grade)as总成绩fromSCwhereSnoin(selectSnofromSCgroupby

4、Snohavingcount(*)3)andGrade=60groupbySnoorderby总成绩desc12检索多于3名学生选修的并以3结尾的课程号的平均成绩。selectavg(Grade)as平均成绩fromSCwhereolike%3groupbyohavingcount(o)313检索最高分与最低分之差大于5分的学生的*、最高分、最底分。selectdistinctSC.Sno*,Sname,ma*(grade)as最高分,min(grade)as最低分fromStudent,SCwhereSC.Sno=Student.SnogroupbySC.Sno,Snamehavingma*

5、(grade)-min(grade)514外连接对实验二中的表6和表7做一个外连接查询,显示每门课程的课号、课名、选修该门课的*、成绩,没有同学选修的课程如Visual_Basic也要在查询结果中。selectc.o课号,ame课名,Sno*,Grade成绩fromCoursecleftouterjoinSCon (c.o=SC.o)15创立一个表Student_other,构造同Student,输入假设干记录,局部记录和Student表中的一样。创立过程:createtableStudent_other(Snochar(8)primarykey,Snamevarchar(8)notnull,

6、Se*char(2)notnull,Birthsmalldatetimenotnull,Classnochar(3)notnull,Entrance_datesmalldatetimenotnull,Home_addrvarchar(40),Sdeptchar(2)notnull,Postcodechar(6)随意输入几条Student表中没有的信息,完成创立 a.查询同时出现在Student表和Student_other表中的记录select*fromstudent_otherso,Studentswhereso.Sno=s.Sno b. 查询Student表和Student_other表中

7、的全部记录select*fromstudentunionselect*fromstudent_other16选作创立一个数据库Student_info_other,参数自定。创立过程: 新建数据库名称确定,参数自定义,然后确定即可a.当前数据库为Student_info,将Student_info数据库中的Student_other复制到Student_info_other中。select*intoStudent_info_other.dbo.Student_otherfromStudent_info.dbo.Student_other b.查询同时出现在Student表和Student_info_other数据库Student_other表中的记录。select*fromStudent_info_other.dbo.student_otherso,Student_info.dbo.Studentswhereso.sno=s.sno. z

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号