1 / 6
文档名称:

sql数据库嵌套查询.doc

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

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

分享

预览

sql数据库嵌套查询.doc

上传人:cxmckate1 2016/7/27 文件大小:0 KB

下载得到文件列表

sql数据库嵌套查询.doc

文档介绍

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