


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验五 数据库综合查询一、实验目的1. 掌握SELECT语句的基本语法和查询条件表示方法;2. 掌握查询条件种类和表示方法;3. 掌握连接查询的表示及使用;4. 掌握嵌套查询的表示及使用;5. 了解集合查询的表示及使用。二、实验内容1. 了解SELECT语句的基本语法格式和执行方法;2. 以数据库原理实验 5数据为基础,请使用 T-SQL 语句实现进行相应操作;3. 完成实验报告。三、实验步骤1. 查询以数据 _开头 , 且倒数第 3 个字符为结的课程的详细情况 select *from coursewhere Cname like 数据 _%结_ escape 2. 查询名字中第 2 个字为
2、阳的学生姓名和学号及选修的课程号、课程名; select sname 姓名 , 学号 , 课程号 , 课程名from student , course , scwhere = and = and sname like _ 阳 %3. 列出选修了数学或者大学英语的学生学号、姓名、所在院系、选修 课程号及成绩;select , sname, sdept , cno, gradefrom student ,scwhere = and cno IN( select cno from course where cname = 数学 ORCNAME= 大学英语 )4. 查询缺少成绩的所有学生的详细情况 ;
3、 select *from student where not exists( select *from scwhere sno = and grade is not null)select *from studentwhere sno in(select snofrom scwhere grade is null)5. 查询与张力 (假设姓名唯一 ) 年龄不同的所有学生的信息;select b .*from student a , student bwhere = 张力 and 6. 查询所选课程的平均成绩大于张力的平均成绩的学生学号、姓名及平均成 绩;select , sname, 平均成
4、绩 =avg( grade )from student ,scwhere =group by , snamehaving avg ( grade )(select avg ( grade )from scwhere sno =(select snofrom studentwhere sname = 张力 )7. 按照“学号,姓名,所在院系, 已修学分” 的顺序列出学生学分的获得情况 其中已修学分为考试已经及格的课程学分之和;select 学号 , sname 姓名 , sdept 院系 , 已修学分 =sum( credit )from student , course , scwhere =
5、 and = and grade =60group by , sname, sdept8. 列出只选修一门课程的学生的学号、姓名、院系及成绩;select 学号 , sname 姓名 , sdept 院系 , gradefrom student ,scwhere = and in(select snofrom scgroup by snohaving count ( cno )= 1)9. 查找选修了至少一门和张力选修课程一样的学生的学号、姓名及课程号;select distinct student .*from studentwhere sno in(select snofrom scwhe
6、re cno in(select cnofrom coursewhere cname = 数据库 or cname = 数据结构 )10. 只选修“数据库”和“数据结构”两门课程的学生的基本信息;select , gradefrom student x ,sc y , course zwhere = and =11. 至少选修“数据库”或“数据结构”课程的学生的基本信息; select * from student ,sc, course where = and = and cname = 数据库 orcname= 数据结构 12. 列出所有课程被选修的详细情况, 包括课程号、 课程名、学号、
7、姓名及成绩;select , gradefrom student ,sc, coursewhere =and =13. 查询只被一名学生选修的课程的课程号、课程名;select cno , cnamefrom course where cno in ( select cno from sc group by cnohaving count ( sno)= 1)14. 使用嵌套查询列出选修了“数据结构”课程的学生学号和姓名;select sno , snamefrom studentwhere sno in( select snofrom sc where cno in ( select cno
8、 from coursewhere cname = 数据结构 )15. 使用嵌套查询查询其它系中年龄小于 CS 系的某个学生的学生姓名、年龄和 院系;select sname , sage , sdeptfrom studentwhere sage ( select max( sage)from studentwhere sdept =csand sdept cs )16. 使用ANY ALL查询,列出其他院系中比CS系所有学生年龄小的学生;select sname , sagefrom studentwhere sage any( select min( sage)from studentw
9、here sdept =csand sdept cs )select sname , sagefrom studentwhere sage all( select sagefrom studentwhere sdept =csand sdept cs )17. 分别使用连接查询和嵌套查询,列出与张力在一个院系的学生的信息;select *from studentwhere sdept =( select sdeptfrom studentwhere sname = 张力 )18. 使用集合查询列出CS系的学生以及性别为女的学生名单;select sname from student where sdept =cs union select sname from studentwhere ssex = 女 19. 使用集合查询列出CS系的学生与年龄不大于19岁的学生的交集、差集;select *from studentwhere sdept =csin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 麦当劳新年店庆活动方案
- 集团游戏活动方案
- 广东软考试题及答案
- 高考试题及答案江苏
- 费用预算编制与成本控制管理模板
- 风险管理评估矩阵模板全面风险识别
- 写景作文迷人的秋色250字10篇范文
- (正式版)DB15∕T 3653-2024 《寒区退化草地改良技术规范》
- 《光合作用机制及其意义:高中生物基础教案》
- 质量控制检查表产品质量检测模板
- 第一章-发型发展简史
- 智能计算系统:从深度学习到大模型 第2版课件 9、第九章-大模型计算系统
- 企业所得税汇算清缴政策培训会课件-于永勤
- 《北京市道路桥梁试验检测费用定额》
- 2024年下半年湖北黄冈黄梅县事业单位招聘“三支一扶”服务期满人员17人易考易错模拟试题(共500题)试卷后附参考答案
- 《小儿神经系统查体》课件
- 农业行政执法工作指南
- 小学体育教案《50米快速跑(途中跑)》
- 高职计算机专业人工智能技术应用与开发
- 地铁接触网检修工技能竞赛考试题库500题(含答案)
- 高考3000词分层分类记忆初中1500
评论
0/150
提交评论