数据库的嵌套查询实验报告_第1页
数据库的嵌套查询实验报告_第2页
数据库的嵌套查询实验报告_第3页
数据库的嵌套查询实验报告_第4页
数据库的嵌套查询实验报告_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验三:数据库的嵌套查询实验实验目的:加深对嵌套查询语句的理解。实验内容:使用IN、比拟符、ANY或ALL和EXISTS操作符进行嵌套查询操作。实验步骤:一.使用带IN谓词的子查询1.查询与’刘晨’在同一个系学习的学生的信息:比拟select*fromstudentwheresdeptin(selectsdeptfromstudentwheresname='刘晨')与:select*fromstudentwheresdept=(selectsdeptfromstudentwheresname='刘晨')的异同比拟:select*fromstudentwheresdept=(selectsdeptfromstudentwheresname='刘晨')andsname<>‘刘晨’与:selectS1.*fromstudentS1,studentS2whereS1.sdept=S2.sdeptandS2.sname='刘晨'的异同2.查询选修了课程名为’信息系统’的学生的学号和姓名:比拟selectsno,snamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromcoursewherecname='信息系统'))与:selectsno,snamefromstudentwheresnoin(selectsnofromsc,coursewheresco=courseoandcname='信息系统')3.查询选修了课程’1’和课程’2’的学生的学号:selectsnofromstudentwheresnoin(selectsnofromscwherecno='1')andsnoin(selectsnofromscwherecno='2')比拟:查询选修了课程’1’或课程’2’的学生的sno:selectsnofromscwherecno='1'orcno='2'比拟连接查询:selectA.snofromscA,scBwhereA.sno=B.snoandAo='1'andBo='2'二.使用带比拟运算的子查询

4.查询比’刘晨’年龄小的所有学生的信息:select*fromstudentwheresage<(selectsagefromstudentwheresname='刘晨')三.使用带Any,All谓词的子查询5.查询其他系中比信息系(IS)某一学生年龄小的学生姓名和年龄;selectsname,sagefromstudentwheresage<Any(selectsagefromstudentwheresdept='IS')andsdept<>'IS'6.查询其他系中比信息系(IS)学生年龄都小的学生姓名和年龄:selectsname,sagefromstudentwheresage<ALL(selectsagefromstudentwheresdept='IS')andsdept<>'IS'7.查询与计算机系(CS)系所有学生的年龄均不同的学生学号,姓名和年龄:selectsno,sname,sagefromstudentwheresage<>all(selectsagefromstudentwheresdept='CS')四.使用带Exists谓词的子查询和相关子查询8.查询与其他所有学生年龄均不同的学生学号,姓名和年龄:selectsno,sname,sagefromstudentAwherenotexists

(select*fromstudentBwhereA.sage=B.sageandA.sno<>B.sno)9.查询所有选修了1号课程的学生姓名:selectsnamefromstudentwhereexists(select*fromscwheresno=student.snoandcno='1')10.查询没有选修了1号课程的学生姓名:selectsnamefromstudentwherenotexists(select*fromscwheresno=student.snoandcno='1')11.查询选修了全部课程的学生姓名:SQLServer中:selectsnamefromstudentwherenotexists(select*fromcoursewherenotexists(select*fromscwheresno=student.snoandcno=courseo))11.查询至少选修了学生95002选修的全部课程的学生的学号:SQLServer中:selectdistinctsnofromscAwherenotexists(select*fromscBwheresno='95002'andnotexists(select*fromscCwheresno=A.snoandcno=Bo))12.求没有人选修的课程号cno和cnamecname:selectcno,cnamefromcourseCwherenotexists(select*fromscwheresco=Co)13*.查询满足条件的(sno,cno)对,其中该学号的学生没有选修该课程号cno的课程SQLServer中:selectsno,cnofromstudent,coursewherenotexists(select*fromscwherecno=courseoandsno=student.sno)14*.查询每个学生的课程成绩最高的成绩信息(sno,cno,grade):select*fromscAwheregrade=(select

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论