数据库实验四:SQL数据查询 下载本文

(27)使用NOT IN运算的简单嵌套查询 select 教师.姓名 from 教师

where 教师.教师编号 not in ( select 课程.责任教师 from 课程

where 课程性质='专业基础')

(28)使用关系运算(如等于)的简单嵌套查询 select 教师.姓名 from 教师

where 教师.教师编号=( select 课程.责任教师 from 课程

where 课程编号='02')

(29)使用ANY或SOME的简单嵌套查询 select 姓名 from 教师

where 工资>= any ( select 工资 from 教师

where 教师编号=20118) select * from 教师

(30) 使用ALL的简单嵌套查询。

select 姓名 from 教师

where 工资>= all (select 工资 from 教师

where 教师编号=20115)

(31)查询院系名称含“计科系”、职称为教授、所负责教程为专业基础的教师姓名、职称、课程名称和课程学时等信息(分别用嵌套查询和连接查询完成,分析各自的效率) select 姓名,课程名称,学时 from 教师 join 课程

on 责任教师=教师编号 join 院系 on 院系.编号=教师.院系

where 名称='计科系' and 职称='教授'

(32)设计两个内外层互相关的嵌套查询。 select * from 教师

select 教师编号,姓名,性别,职称,工资 from 教师 out where 工资=

(select max(工资) from 教师 innera

where out.教师编号= innera.教师编号 )

(33)使用EXISTS的嵌套查询。 select * from 教师

where exists (select * from 课程

where 课程.责任教师=教师.教师编号)