实验五 数据库综合查询(学生).doc

上传人:李医生 文档编号:5655447 上传时间:2020-07-20 格式:DOC 页数:5 大小:33KB
返回 下载 相关 举报
实验五 数据库综合查询(学生).doc_第1页
第1页 / 共5页
实验五 数据库综合查询(学生).doc_第2页
第2页 / 共5页
实验五 数据库综合查询(学生).doc_第3页
第3页 / 共5页
实验五 数据库综合查询(学生).doc_第4页
第4页 / 共5页
实验五 数据库综合查询(学生).doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《实验五 数据库综合查询(学生).doc》由会员分享,可在线阅读,更多相关《实验五 数据库综合查询(学生).doc(5页珍藏版)》请在三一文库上搜索。

1、实验五 数据库综合查询一、实验目的1. 掌握SELECT语句的基本语法和查询条件表示方法;2. 掌握查询条件种类和表示方法;3. 掌握连接查询的表示及使用;4. 掌握嵌套查询的表示及使用;5. 了解集合查询的表示及使用。二、实验内容1. 了解SELECT语句的基本语法格式和执行方法;2. 以数据库原理实验5数据为基础,请使用T-SQL 语句实现进行相应操作;3. 完成实验报告。三、实验步骤1. 查询以数据_开头,且倒数第3个字符为结的课程的详细情况 select*from coursewhere Cname like 数据_%结_escape2. 查询名字中第2个字为阳的学生姓名和学号及选修的

2、课程号、课程名; select sname 姓名,student.sno 学号,o 课程号,ame 课程名from student,course,sc where student.sno=sc.sno and o=o and sname like_阳%3. 列出选修了数学或者大学英语的学生学号、姓名、所在院系、选修课程号及成绩; select student.sno,sname,sdept,cno,gradefrom student,scwhere student.sno=sc.sno and cno IN(select cno from course where cname=数学OR CNA

3、ME=大学英语)4. 查询缺少成绩的所有学生的详细情况; select*from student where not exists(select*from sc where sno=student.sno and grade is not null)select*from student where sno in(select sno from sc where grade is null)5. 查询与张力(假设姓名唯一)年龄不同的所有学生的信息; select b.*from student a,student b where a.sname=张力and a.sageb.sage6. 查询所

4、选课程的平均成绩大于张力的平均成绩的学生学号、姓名及平均成绩; select student.sno,sname,平均成绩=avg(grade)from student,sc where sc.sno=student.sno group by student.sno,sname having avg(grade)(select avg(grade)from sc where sno=(select sno from student where sname=张力)7. 按照“学号,姓名,所在院系,已修学分”的顺序列出学生学分的获得情况。其中已修学分为考试已经及格的课程学分之和; select s

5、tudent.sno 学号,sname 姓名,sdept 院系,已修学分=sum(credit)from student,course,sc where student.sno=sc.sno and o=o and grade=60 group by student.sno,sname,sdept8. 列出只选修一门课程的学生的学号、姓名、院系及成绩; select student.sno 学号,sname 姓名,sdept 院系,gradefrom student,sc where student.sno=sc.sno and sc.sno in(select sno from sc gro

6、up by sno having count(cno)=1)9. 查找选修了至少一门和张力选修课程一样的学生的学号、姓名及课程号; select distinct student.*from student where sno in(select sno from sc where cno in(select cno from course where cname=数据库or cname=数据结构)10. 只选修“数据库”和“数据结构”两门课程的学生的基本信息; select o,ame,x.sno,x.sname,grade from student x,sc y,course z wher

7、e x.sno=y.sno and o=o11. 至少选修“数据库”或“数据结构”课程的学生的基本信息;select *from student,sc,coursewhere student.sno=sc.snoand o=oand cname=数据库orcname=数据结构12. 列出所有课程被选修的详细情况,包括课程号、课程名、学号、姓名及成绩; select o,ame,student.sno,student.sname,gradefrom student,sc,coursewhere student.sno=oand o=o13. 查询只被一名学生选修的课程的课程号、课程名; sele

8、ct cno,cnamefrom coursewhere cno in(select cnofrom scgroup by cnohaving count(sno)=1)14. 使用嵌套查询列出选修了“数据结构”课程的学生学号和姓名; select sno,snamefrom studentwhere sno in(select snofrom scwhere cno in(select cnofrom coursewhere cname=数据结构)15. 使用嵌套查询查询其它系中年龄小于CS系的某个学生的学生姓名、年龄和院系; select sname,sage,sdeptfrom stud

9、entwhere sage(select max(sage)from studentwhere sdept=csand sdeptcs)16. 使用ANY、ALL 查询,列出其他院系中比CS系所有学生年龄小的学生; select sname,sagefrom studentwhere sageany(select min(sage)from studentwhere sdept=csand sdeptcs)select sname,sagefrom studentwhere sageall(select sagefrom studentwhere sdept=csand sdeptcs)17.

10、 分别使用连接查询和嵌套查询,列出与张力在一个院系的学生的信息; select*from studentwhere sdept=(select sdeptfrom studentwhere sname=张力)18. 使用集合查询列出CS系的学生以及性别为女的学生名单; select snamefrom studentwhere sdept=csunionselect snamefrom studentwhere ssex=女19. 使用集合查询列出CS系的学生与年龄不大于19岁的学生的交集、差集; select*from studentwhere sdept=csintersectselect*from studentwhere sage=1920. 使用集合查询列出选修课程1的学生集合与选修课程2的学生集合的交集; select snofrom scwhere cno=1intersectselect snofrom scwhere cno=2

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

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1