in谓词子查询
select * from dbo.Worker where did in (select dID from DepartMent)
比较运算子查询
select * from Worker where did > (select Avg(did) from DepartMent) --any其中一个成立 select * from Worker where did > all(select did from DepartMent where did<4) --all全部成立 select * from Worker where did > all(select did from DepartMent where did<2)
子查询代替表达式
select wName,AVG(Gender.Gid) from Worker inner join dbo.Gender on Worker.gid = Gender.Gid group by wName --等同于 select wName,(select avg(Gid) from Gender where Gender.Gid = Worker.Gid ) from Worker
exists子查询
--存在
select * from Worker where exists(select * from Gender where 1=2) select * from Worker where exists(select * from Gender where 1=1) --不存在 select * from Worker where not exists(select * from Gender where 1=2) select * from Worker where not exists(select * from Gender where 1=1)