已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年苗栗县辅警招聘考试真题附答案详解
- 2025年甘南州辅警招聘考试题库含答案详解
- 2025年葫芦岛辅警招聘考试题库含答案详解(达标题)
- 2025年钦州辅警协警招聘考试真题附答案详解(夺分金卷)
- 2025年文化创意行业文化创意产业数字内容运营研究报告及未来发展趋势预测
- 2025年玉林辅警招聘考试真题含答案详解(模拟题)
- 2025年智能医疗产业智能医疗服务与健康管理研究报告及未来发展趋势预测
- 2025年阳泉辅警协警招聘考试真题含答案详解(综合卷)
- 2025年智能家居行业智能家居与智能化生活研究报告及未来发展趋势预测
- 2025年游戏行业游戏直播平台分析研究报告及未来发展趋势预测
- 无人机植保技术课件:无人机植保现状
- 代开发票合作合同
- 广东省珠海市文园中学2025届数学七上期末学业质量监测试题含解析
- 产能分析表完整版本
- 中职婴幼儿托育人才培养方案
- 企业数据治理体系和应用场景案例
- 蔡司手术显微镜课件
- 抛光机使用说明书
- 教科版小学科学六年级上册《纸桥承重》课件
- VDA6.3-2016过程审核主要证据清单
- 小学四年级数学上册促销问题
评论
0/150
提交评论