SQL语句嵌套查询实例

use stu
--1
select sno,cno,grade
from	sc
where sno in (
			select sno
			from student
			where sdept = 'CS'
			) 
--2
select cno
from course
where cno in(
			select cno
			from sc
			where sno in ( select sno from student where sname='李勇')	
			)
--3
select sno
from student
where sno in (select sno from sc where cno='1') And sno in(select sno from sc where cno='2')
--4
select sno,sname
from student
where sno not in (select sno from sc)
--5
select sno,grade
from sc
where cno in(select cno from course where cname='数据库')
--6
select cno,grade
from sc
where grade >= ALL(select grade from sc where sno = '201215121')
--7
select sum(grade)
from sc
where sno in (select sno from student where sdept='CS') and cno = (select cno from course where cname='信息系统')
--8
select sno,grade
from sc
where sno in (select sno from student where sname='李勇') and cno = (select cno from course where cname='数据库')
--9
select cno,cname
from course
where cno not in (select cno from sc where sno='201215121')
--10
select sno,sname,sdept
from student
where sno in (select sno from sc group by sno having count(cno)>=2)
posted @ 2025-04-24 08:41  嘉君  阅读(77)  评论(0)    收藏  举报