1、IN谓词子查询:
select Sno,Sname,Sdept from Student
where sdept IN
(select Sdept
from Student
where Sname =’WANG’);
select Sno,Sname from Student
where Sno IN
(select Sno
from SC
where Cno IN
(select Cno
from Course
where Cname =’shujuku4′)
);
2、ANY(SOME)或ALL谓词子查询:
select Sname,Sage from Student
where Sage < ANY (select Sage
from Student
where Sdept =’CS’)
AND Sdept <> ‘CS’;
3、EXISTS谓词子查询:
select Sname from Student
where EXISTS
(select *
from SC
where Sno =Student.Sno AND Cno=’1′);
Tags: mysql, sql, 数据库
select DISTINCT Sno from SC SCX
where NOT EXISTS
(select *
from SC SCY
where SCY.Sno =’1002′ AND NOT EXISTS
(select *
from SC SCZ
where SCZ.Sno = SCX.Sno AND
SCZ.Cno = SCY.Cno));

No Comments Now!
Be the first to comment on this entry.