全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验五:数据库综合查询一、实验目的1. 掌握SELECT语句的基本语法和查询条件表示方法;2. 掌握查询条件种类和表示方法;3. 掌握连接查询的表示及使用;4. 掌握嵌套查询的表示及使用;5. 了解集合查询的表示及使用。二、实验环境已安装SQL Server企业版的计算机(120台);具有局域网环境,有固定IP;三、实验学时2学时四、实验要求1. 了解SELECT语句的基本语法格式和执行方法;2. 了解连接查询的表示及使用;3. 了解嵌套查询的表示及使用;4. 了解集合查询的表示及使用;5. 完成实验报告;五、实验内容及步骤1.利用Transact-SQL嵌套语句实现下列数据查询操作。(选课表2) 1) 查询选修了计算机体系结构的学生的基本信息。select * from student,course where ame=(select cname from course where cname=计算机体系结构) 2) 查询年龄比李勇小的学生的学号和成绩。 select sc.snum,score from sc,student where sage (select sage=min(sage) from student where dnum=d1 )and dnum!=d1 4) 查询其他系中比系编号为D3的学生年龄都大的学生的姓名。select sname from student where sage(select sage=max(sage) from student where dnum=d3 )and dnum!=d35) 查询C1课程的成绩高于70的学生姓名。select distinct sname from student,sc where score70 and cnum=c1and student.snum=sc.snum6) 查询C1课程的成绩不高于70的学生姓名。 select distinct sname from student,sc where score=2)10)查询开设的课程和选修该课程的学生的总成绩、平均成绩、最高成绩和最低成绩。select cname,sum=sum(score),avg=avg(score),max=max(score),min=min(score) from sc,course group by cname(二)、以数据库原理实验4数据为基础,请使用T-SQL 语句实现进行以下操作:(student1)1. 查询以DB_开头,且倒数第3个字符为s的课程的详细情况; select * from course where cname like db_%s_2. 查询名字中第2个字为阳的学生姓名和学号及选修的课程号、课程名; select sname,student.sno,o,cname from student,sc,course where sname like _阳% and student.sno=sc.sno and o=o3. 列出选修了数学或者大学英语的学生学号、姓名、所在院系、选修课程号及成绩; select student.sno,sname,sdept,o,cname from student,course where cname=数学 or cname=大学英语4. 查询缺少成绩的所有学生的详细情况; select * from student,sc where sc.grade is null and sc.sno=student.sno5. 查询与张力(假设姓名唯一)年龄不同的所有学生的信息; select * from student where sage!=(select sage from student where sname=张力)6. 查询所选课程的平均成绩大于张力的平均成绩的学生学号、姓名及平均成绩; 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 student.sno,sname,sdept,已修学分=sum(ccredit) from student,course,sc where o=o and sc.sno=student.sno and grade=60 group by student.sno,sname,sdept8. 列出只选修一门课程的学生的学号、姓名、院系及成绩; select student.sno,sname,sdept,grade from student,sc where sc.sno=student.sno and student.sno in (select sno from sc group by sno having count(*)=1) 9. 查询选修“数据库”或“数据结构”课程的学生的基本信息; select * from student where sno in (select sno from sc where cno in (select cno from course where cname=数据库 or cname=数据结构)10. 列出所有课程被选修的详细情况,包括课程号、课程名、学号、姓名及成绩; select distinct o,ame,student.sno,sname,grade from course,sc,student where student.sno=sc.sno and o=o 11. 查询只被一名学生选修的课程的课程号、课程名; select cno,cname from course where cno in (select cno from sc group by cno having count (cno)=1)12. 检索所学课程包含学生张向东所学课程的学生学号、姓名; select distinct student.sno,sname from student,sc where sc.sno=student.sno and cno in (select cno from sc where sno in(select sno from student where sname=张向东)13. 检索所学课程包含学生张向东所学全部课程的学生学号、姓名; select distinct student.sno,sname from student,sc where sc.sno=student.sno and cno in (select cno from sc where sno in(select sno from student where sname=张向东) and sname != 张向东 group by sc.sno,student.sno,sname having count(cno) =(select count(cno) from sc where sno=(select sno from student where sname=张向东)14. 使用嵌套查询列出选修了“数据结构”课程的学生学号和姓名; select sno,sname from student where sno in (select sno from sc where cno in (select cno from course where cname=数据结构)15. 使用嵌套查询查询其它系中年龄小于CS系的某个学生的学生姓名、年龄和院系;select sname,sage,sdept from student where sage (select max(sage) from student where sdept=cs) and sdept !=cs16. 使用ANY、ALL 查询,列出其他院系中比CS系所有学生年龄小的学生; select sname,sage from student where sage any (select min(sage) from student where sdept=cs) and sdept !=csselect sname,sage from student where sage all (select sage from student where sdept=cs) and sdept !=cs17. 分别使用连接查询和嵌套查询,列出与张力在一个院系的学生的信息; 连接查询: select * from student x,student y where x.sdept=y.sdept and x.sname=张力 嵌套查询: select * from student where sdept in (select sdept from student where sname=张力)18. 使用集合查询列出CS系的学生以及性别为女的学生名单; select sname from student where sdept=cs union select sname from student where ssex=女19. 使用集合查询列出CS系的学生与年龄不大于19岁的学生的交集、差集; 交集:select * from student where sdept=cs intersect select * from stuednt where sgae
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026重庆面向西北工业大学定向选调应届毕业生历年真题汇编附答案解析
- 2025北京东方电气北方分公司招聘1人参考题库带答案解析
- 2026年陕西省选调生招录(面向哈尔滨工业大学)模拟试卷附答案解析
- 2025年滁州市第一人民医院公开招聘编外工作人员5人备考公基题库带答案解析
- 2025四川省第四地质大队下半年考核招聘工作人员10人笔试备考试卷附答案解析
- 2025华夏银行成都分行社会招聘(11月)模拟试卷附答案解析
- 2026“梦想靠岸”招商银行东莞分行冬季校园招聘笔试备考试卷带答案解析
- 2025四川阿坝州茂县教育局下半年考核招聘紧缺学科教师16人备考公基题库带答案解析
- 2025四川广安市岳池县党史县志办公室招募见习生1人备考题库带答案解析
- 2026山东青岛平度市教育体育系统“平选计划”120人笔试模拟试卷带答案解析
- 医院十五五发展规划汇编
- 健康养生讲座课件
- “十五五”林业发展规划
- T/CIE 166-2023企业级固态硬盘测试规范第2部分:性能测试
- 咽喉常见疾病科普
- 2025年广西公需科目答案02
- 结伴旅游免责协议书
- 部编版新教材三年级上册《20.古诗三首》教案(鹿柴、望天门山、饮湖上初晴后雨)
- 化妆品色彩课件
- 《京东运营大全》课件
- 中国老年高血压管理指南(2023版)解读
评论
0/150
提交评论