2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
1 / 17
2021年数据库的嵌套查询实验报告
试验三: 数据库嵌套查询试验
试验目:
加深对嵌套查询语句了解。
试验内容:
使用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='刘晨') and sname <> ‘刘晨’
与: select S1.* from student S1, student S2 where = and ='刘晨'异同
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
2 / 17
2021年数据库的嵌套查询实验报告
2. 查询选修了课程名为’信息系统’ 学生学号和姓名:
比较select sno, sname from student where sno in
(select sno from sc where cno in (select cno from course where cname='信息系统'))
与: select sno, sname from student where sno in
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
3 / 17
2021年数据库的嵌套查询实验报告
(select sno from sc, course where = and cname='信息系统')
3. 查询选修了课程’1’和课程’2’学生学号:
select sno from student where sno in (select sno from sc where cno='1')
and sno in (select sno from sc where cno='2')
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
4 / 17
2021年数据库的嵌套查询实验报告
比较: 查询选修了课程’1’或课程’2’学生sno:
select sno from sc where cno='1' or cno='2'
比较连接查询:
select from sc A, sc B where = and ='1' and ='2'
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
5 / 17
2021年数据库的嵌套查询实验报告
二. 使用带比较运算子查询
4. 查询比’刘晨’年纪小全部学生信息:
select * from student where sage<
(select sage from student where sname='刘晨')
三. 使用带Any, All谓词子查询
5. 查询其她系中比信息系(IS)某一学生年纪小学生姓名和年纪;
select sname, sage from student where sage <Any
(select sage from student where sdept='IS') and sdept<>'IS'
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
6 / 17
2021年数据库的嵌套查询实验报告
6. 查询其她系中比信息系(IS)学生年纪都小学生姓名和年纪:
select sname, sage from student where sage <ALL
(select sage from student where sdept='IS') and sdept<>'IS'
2021年数据库的嵌套查询实验报告
2021年数据库的嵌套查询实验报告
7 / 17
2021年数据库的嵌套查询实验报告
7.
2022年数据库的嵌套查询实验报告 来自淘豆网m.daumloan.com转载请标明出处.