实验4:数据库的嵌套查询,数据库的嵌套查询实验,数据库嵌套查询,数据库嵌套查询语句,数据库嵌套查询面试题,数据库连接查询,数据库创建嵌套查询,sql嵌套查询例题,数据库嵌套查询实验报告,数据库语言连接查询等同于嵌套学号: 姓名:
实验四:数据库的嵌套查询实验
实验目的:
加深对嵌套查询语句的理解。
实验内容:
使用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='刘晨') and sname<>'刘晨’
比较: select S1.* from student S1, student S2 where = and ='刘晨'
结果:
查询选修了课程名为’信息系统’的学生的学号和姓名:
答: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'
结果:第一类的查询结果为’95001’和’95004’;第二类查询结果有7种(包含重复);最后一类利用自连接查询结果有两种。
二. 使用带比较运算的子查询
查询比’刘晨’年龄小的所有学生的信息:
答:select * from student
where sage <
(select sage from student
where sname = '刘晨' )
三. 使用带Any, All谓词的子查询(对于ALL全称量词,建议改成否定之否定存在量词)
查询其他系中比信息系(IS)某一学生年龄小的学生姓名和年龄;
答:select sname, sage
from student
where sdept <> 'IS' and
sage
实验4:数据库的嵌套查询 来自淘豆网m.daumloan.com转载请标明出处.