数据库的嵌套查询实验报告.doc

数据库的嵌套查询实验报告.doc

ID:56773376

大小:1.06 MB

页数:17页

时间:2020-07-08

数据库的嵌套查询实验报告.doc_第1页
数据库的嵌套查询实验报告.doc_第2页
数据库的嵌套查询实验报告.doc_第3页
数据库的嵌套查询实验报告.doc_第4页
数据库的嵌套查询实验报告.doc_第5页
资源描述:

《数据库的嵌套查询实验报告.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、实验三:数据库的嵌套查询实验实验目的:加深对嵌套查询语句的理解。实验内容:使用IN、比较符、ANY或ALL和EXISTS操作符进行嵌套查询操作。实验步骤:一.使用带IN谓词的子查询1.查询与’刘晨’在同一个系学习的学生的信息:比较select*fromstudentwheresdeptin(selectsdeptfromstudentwheresname='刘晨')与:select*fromstudentwheresdept=(selectsdeptfromstudentwheresname='刘晨')的异同比较:select*fromstudentwhe

2、resdept=(selectsdeptfromstudentwheresname='刘晨')andsname<>‘刘晨’与:selectS1.*fromstudentS1,studentS2whereS1.sdept=S2.sdeptandS2.sname='刘晨'的异同2.查询选修了课程名为’信息系统’的学生的学号和姓名:比较selectsno,snamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromcoursewherecname='信息系统'))与:selectsno,sn

3、amefromstudentwheresnoin(selectsnofromsc,coursewheresc.cno=course.cnoandcname='信息系统')3.查询选修了课程’1’和课程’2’的学生的学号:selectsnofromstudentwheresnoin(selectsnofromscwherecno='1')andsnoin(selectsnofromscwherecno='2')比较:查询选修了课程’1’或课程’2’的学生的sno:selectsnofromscwherecno='1'orcno='2'比较连接查询:selec

4、tA.snofromscA,scBwhereA.sno=B.snoandA.cno='1'andB.cno='2'二.使用带比较运算的子查询4.查询比’刘晨’年龄小的所有学生的信息:select*fromstudentwheresage<(selectsagefromstudentwheresname='刘晨')三.使用带Any,All谓词的子查询5.查询其他系中比信息系(IS)某一学生年龄小的学生姓名和年龄;selectsname,sagefromstudentwheresage

5、IS')andsdept<>'IS'6.查询其他系中比信息系(IS)学生年龄都小的学生姓名和年龄:selectsname,sagefromstudentwheresage'IS'7.查询与计算机系(CS)系所有学生的年龄均不同的学生学号,姓名和年龄:selectsno,sname,sagefromstudentwheresage<>all(selectsagefromstudentwheresdept='CS')四.使用带Exists谓词的子查询和相关子

6、查询8.查询与其他所有学生年龄均不同的学生学号,姓名和年龄:selectsno,sname,sagefromstudentAwherenotexists(select*fromstudentBwhereA.sage=B.sageandA.sno<>B.sno)9.查询所有选修了1号课程的学生姓名:selectsnamefromstudentwhereexists(select*fromscwheresno=student.snoandcno='1')10.查询没有选修了1号课程的学生姓名:selectsnamefromstudentwherenotexis

7、ts(select*fromscwheresno=student.snoandcno='1')11.查询选修了全部课程的学生姓名:SQLServer中:selectsnamefromstudentwherenotexists(select*fromcoursewherenotexists(select*fromscwheresno=student.snoandcno=course.cno))11.查询至少选修了学生95002选修的全部课程的学生的学号:SQLServer中:selectdistinctsnofromscAwherenotexists(sel

8、ect*fromscBwheresno='95002'andnot

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。