




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验六:数据查询语言实验目的体会SQL语言数据查询功能的丰富和复杂。实验内容SQL数据查询语句: 例3-1:(子查询) 求与 刘晨 年龄相同的学生的姓名和系。 select sname,sdept from student where Sage in(select Sage from student where Sname=刘晨)and sname 刘晨; 例3-2:(子查询) 求选修了课程名为 数据结构 的学生的学号和姓名。 select sno,sname from student where sno in (select sno from sc where cno in(select cno from course where cname=数据结构); 例3-3:(子查询ANY) 求比数学系中某一学生年龄大的学生的姓名和系。 select sname,sdept from student where sage any(select sage from student where sdept=ma) and sdept ma; 例3-4:(子查询ALL) 求比数学系中全体学生年龄大的学生的姓名和系。 select sname,sdept from student where sage all (select sage from student where sdept=ma); 例3-5:(子查询EXISTS) 求选修了课程004的学生的姓名和系。 select sname,sdept from student where exists (select * from sc where sno=student.sno and cno=004); 例3-6:(返回多列的子查询) 求与 刘晨 同系且同龄的学生的姓名和系。 select sname,sdept from student where sage= (select sage from student where sname=刘晨) intersect select sname,sdept from student where sdept= (select sdept from student where sname=刘晨) and sname 刘晨;例3-7:(多个子查询) 求与 刘晨 同系,且年龄大于 李小飞 的学生的信息。 select * from student where sdept=(select sdept from student where sname=刘晨) intersect select *from student where sage(select sage from student where sname=李小飞); 例3-8:(子查询中使用表连接) 求数学系中年龄相同的学生的姓名和年龄。 select distinct first.sname,first.sage from student first,student second where first.sdept=maand first.sage=second.sage; 例3-9:(嵌套与分组查询) 检索选修某课程的学生人数多于3人的这门课的课程名。 select cname from Course where Cno=(select cno from sc group by cno having COUNT(*)3); 没有选修某课程的学生人数多于3人的课程,故没有找出符合条件的 例3-10:(集合查询) 列出所有同学的姓名和性别。 select Sname,ssex from student;例3-11:(相关子查询) 求未选修课程004的学生的姓名。 select sname from student where Sno in(select distinct sno from scexceptselect sno from SC where Cno=004);例3-12:(相关子查询) 求选修了全部课程的学生的姓名。 select sname from student where not exists (select * from Course where not exists (select * from SC where Sno=student.Sno and Cno=Co); 没有选择全部课程的学生,故没有找出符合条件的 例3-13:(相关子查询) 求至少选修了学生 200215122 所选修的全部课程的学生的学号。select distinct sno from sc scx where not exists(select * from sc scy where scy.sno=200215122 and not exists (select * from sc scz where scz.sno=scx.sno and o=o); 例3-14:(相关子查询) 求成绩比所选修课程平均成绩高的学生的学号、课程号、和成绩。select Sno,cno,grade from sc xwhere grade = (select AVG(grade)from SC y where y.Sno=x.sno);例3-15:查询被一个以上的学生选修的课程号。select cno from sc group by cnohaving COUNT(*)=1; 例3-16:(相关子查询) 查询所有未选课程的学生姓名和所在系。select sname,sdept from student where Sno in(select distinct sno from studentexcept select distinct sno from sc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 46118-2025农产品批发市场分类与分级指南
- 农业机械安全培训资料课件
- 到校安全规范培训内容课件
- 初试源码编辑器课件
- 内镜科普课件
- 内镜清洗消毒课件
- 初创公司安全感培训内容课件
- 临城软文营销计划方案(3篇)
- 营销策划方案公司(3篇)
- 内部人员安全培训资料课件
- 中医病证诊断疗效标准
- 海姆立克评分标准
- RB/T 040-2020病原微生物实验室生物安全风险管理指南
- GB/T 11021-2007电气绝缘耐热性分级
- 元数据教学讲解课件
- ASCVD时代总体心血管风险评估工具的更新ppt参考课件
- 人工智能导论-课件-第2章知识图谱
- 华中8型数控系统设备连接与参数配置
- 防突管理制度汇编
- 江苏省教育科学规划课题开题报告
- 医疗器械GMP文件PUR-OP-001 Rev 01采购控制程序
评论
0/150
提交评论