1 / 6
文档名称:

sql数据库的嵌套查询.doc

格式:doc   页数:6页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

sql数据库的嵌套查询.doc

上传人:endfrs 2015/10/24 文件大小:0 KB

下载得到文件列表

sql数据库的嵌套查询.doc

文档介绍

文档介绍:实验四:数据库的嵌套查询实验
学号: 姓名:
实验四:数据库的嵌套查询实验
实验目的:
加深对嵌套查询语句的理解。
实验内容:
使用IN、比较符、ANY或ALL和EXISTS操作符进行嵌套查询操作。
实验步骤:
一. 使用带IN谓词的子查询
查询与’刘晨’在同一个系学****的学生的信息:
select * from student where sdept in
(select sdept from student where sname='刘晨')
比较: select * from student where sdept =
(select sdept from student where sname='刘晨') 的异同
比较: select * from student where sdept =
(select sdept from student where sname='刘晨') andsname<>'刘晨V
比较: select S1.* from student S1, student S2 where = and ='刘晨'
查询选修了课程名为’信息系统’的学生的学号和姓名:
SQL Server中: select sno, sname from student where sno in
(select sno from sc o in
(o from course ame='信息系统'))
查询选修了课程’1’和课程’2’的学生的学号(姓名):
select sno from student where sno in (select sno from sc o='1')
and sno in (select sno from sc o='2')
select from SC x ,SC y
where = and o='1' and o='2'
select sno from SC o='1' and sno in (select sno from SC o='2')
比较: 查询选修了课程’1’或课程’2’的学生的sno:
select sno from sc o='1' o='2'
比较连接查询:
select from sc A, sc B where = and o='1' and o='2'
二. 使用带比较运算的子查询
查询比’刘晨’年龄小的所有学生的信息:
select * from student where sage<
(select sage from student where sname='刘晨')
三. 使用带Any, All谓词的子查询(对于ALL全称量词,建议改成否定之否定存在量词)
查询其他系中比信息系(IS)某一学生年龄小的学生姓名和年龄;
select sname, sage from student where sage <Any
(select sage from student where sdept='IS')
and sdept<>'IS'
查询其他系中比信息系(IS)学生年龄