实验五:数据库综合查询

上传人:简****9 文档编号:107017365 上传时间:2019-10-17 格式:DOC 页数:8 大小:56KB
返回 下载 相关 举报
实验五:数据库综合查询_第1页
第1页 / 共8页
实验五:数据库综合查询_第2页
第2页 / 共8页
实验五:数据库综合查询_第3页
第3页 / 共8页
实验五:数据库综合查询_第4页
第4页 / 共8页
实验五:数据库综合查询_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《实验五:数据库综合查询》由会员分享,可在线阅读,更多相关《实验五:数据库综合查询(8页珍藏版)》请在金锄头文库上搜索。

1、实验五:数据库综合查询一、实验目的1. 掌握SELECT语句的基本语法和查询条件表示方法;2. 掌握查询条件种类和表示方法;3. 掌握连接查询的表示及使用;4. 掌握嵌套查询的表示及使用;5. 了解集合查询的表示及使用。二、实验环境已安装SQL Server企业版的计算机(120台);具有局域网环境,有固定IP;三、实验学时2学时四、实验要求1. 了解SELECT语句的基本语法格式和执行方法;2. 了解连接查询的表示及使用;3. 了解嵌套查询的表示及使用;4. 了解集合查询的表示及使用;5. 完成实验报告;五、实验内容及步骤1.利用Transact-SQL嵌套语句实现下列数据查询操作。 1)

2、查询选修了计算机体系结构的学生的基本信息。select * from student where 学号 in (select 学号 from sc where 课程号 in (select 课程号 from course where 课程名称 = 计算机体系结构) 2) 查询年龄比李勇小的学生的学号和成绩。select sc.学号,成绩 from sc,student where sc.学号=student.学号 and student.年龄 any (select 年龄 from student where 系编号=d1 ) and 系编号!=d14) 查询其他系中比系编号为D3的学生年龄都

3、大的学生的姓名。select 姓名 from student where 年龄 in ( select 年龄 from student where 年龄 all (select 年龄 from student where 系编号=d3 ) and 系编号!=d35) 查询C1课程的成绩高于70的学生姓名。select 姓名 from student ,scWhere student.学号 = sc.学号 and sc.成绩 70 and sc.课程号 = C16) 查询C1课程的成绩不高于70的学生姓名。select 姓名 from student ,scwhere student.学号 =

4、sc.学号 and sc.成绩 =2 );10) 查询开设的课程和选修该课程的学生的总成绩、平均成绩、最高成绩和最低成绩。select 课程号,sum(成绩) sum_成绩,avg(成绩) avg_成绩,max(成绩) max_成绩,min(成绩) min_成绩 from sc group by 课程号;(二)、以数据库原理实验4数据为基础,请使用T-SQL 语句实现进行以下操作:1. 查询以DB_开头,且倒数第3个字符为s的课程的详细情况; select * from course where 课程名称 like DB_%s_ escape ;2. 查询名字中第2个字为阳的学生姓名和学号及选

5、修的课程号、课程名; select a.姓名,a.sno,o,b.课程名称 from student a,course b,sc c where a.sno=c.sno and o=o and a.姓名 like _阳%;3. 列出选修了数学或者大学英语的学生学号、姓名、所在院系、选修课程号及成绩; select a.sno,a.姓名,a.sdept,o,b.grade from student a,sc b where a.sno = b.sno and o in ( select cno from course where 课程名称 = 数学 or 课程名称 = 大学英语 );4. 查询缺

6、少成绩的所有学生的详细情况; select * from student where sno in ( select sno from sc where grade is null );5. 查询与张力(假设姓名唯一)年龄不同的所有学生的信息; select a.* from student a,student bwhere b.姓名=张力 and a.年龄b.年龄;6. 查询所选课程的平均成绩大于张力的平均成绩的学生学号、姓名及平均成绩; select a.sno,a.姓名,avg(b.grade) avg_grade from student a,sc bwhere a.sno=b.sno

7、 group by a.sno,a.姓名having avg(b.grade)(select avg(grade) from sc where sno = (select sno from student where 姓名 = 张力)7. 按照“学号,姓名,所在院系,已修学分”的顺序列出学生学分的获得情况。其中已修学分为考试已经及格的课程学分之和; select student.sno 学号,student.姓名 姓名,student.sdept 所在院系 ,sum(course.ccredit) 已修学分 from student,sc,coursewhere student.sno = s

8、c.sno and o = o andsc.grade=60group by student.sno,student.姓名 ,student.sdept;8. 列出只选修一门课程的学生的学号、姓名、院系及成绩; select a.sno,a.姓名,a.sdept,b.grade from student a,sc bwhere a.sno=b.sno and b.sno in (select sno from scgroup by snohaving count(sno)=1);9. 查询选修“数据库”或“数据结构”课程的学生的基本信息; select student.* from stude

9、nt,course,scwhere student.sno=sc.sno and o=o and (course.课程名称 = 数据库 or course.课程名称 = 数据结构);10. 列出所有课程被选修的详细情况,包括课程号、课程名、学号、姓名及成绩;select a.sno,a.姓名,o,b.课程名称,c.grade from student a,course b,sc cwhere a.sno = c.sno and o = o;11. 查询只被一名学生选修的课程的课程号、课程名; select cno,课程名称 from course where cno in (select cn

10、o from scgroup by cno having count(sno)=1); 12. 检索所学课程包含学生张向东所学课程的学生学号、姓名; select sno,姓名 from studentwhere sno in (select sno from sc where cno in (select cno from student,course where 姓名 = 张向东);13. 检索所学课程包含学生张向东所学全部课程的学生学号、姓名; select student.sno,姓名 from studentwhere not exists (select a.sno from sc

11、 awhere a.sno = (select sno from studentwhere 姓名 = 张向东 and not exists (select b.sno from sc bwhere b.sno = student.sno and o = o);14. 使用嵌套查询列出选修了“数据结构”课程的学生学号和姓名; select sno,姓名 from studentwhere sno in (select sno from sc where cno in (select cno from coursewhere 课程名称 = 数据结构);15. 使用嵌套查询查询其它系中年龄小于CS系

12、的某个学生的学生姓名、年龄和院系; select 姓名,年龄,sdept from studentwhere sdept CSand 年龄 (select max(年龄) from student where sdept = CS);16. 使用ANY、ALL 查询,列出其他院系中比CS系所有学生年龄小的学生;-any查询-select * from studentwhere sdept CS and 年龄 any (select min(年龄) from student where sdept = CS);-all查询-select * from studentwhere sdept CS and 年龄 all (select 年龄 from student where sdept = CS); 17. 分别使用连接查询和嵌套查询,列出与张力在一个院系的学生的信息; -连接查询-select a.* from student a,student bwhere b.姓名 = 张力 and a.sdept = b.sdept and a.姓名 张力; -嵌套查询-select * from studentwhere 姓名 张力 and sdept in (select sdept from student where 姓名 = 张力); 18. 使用

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号