数据库中有三个关系(基本本)
s(s#,sname,age,sex)
sc(s#,c#,grade)
c(c,cname,teacher)
检索学习全部课程的学生姓名
实现的语句是:
select sname from s
where not exists
(select * from c
where not exists
(select * from sc
where sc.s#=s.s# and sc.c#=c.c#))
看不懂。请高手帮忙解释一下。谢谢
...全文
504打赏收藏
请大家帮忙解释一下这条sql语句
数据库中有三个关系(基本本) s(s#,sname,age,sex) sc(s#,c#,grade) c(c,cname,teacher) 检索学习全部课程的学生姓名 实现的语句是: select sname from s where not exists (select * from c where not exists (select * from sc where sc.s#=s.s# and sc.c#=c.c#)) 看不懂。请高手帮忙解释一下。谢谢
--查询s3学生没有学习的课程
(select c# from c where not exists(select * from sc where sc.s#='s3' and sc.c#=c.c#))
--某学生没有学习的课程
(select * from c where not exists(select * from sc where sc.s#=s.s# and sc.c#=c.c#))
--不存在没有学习的课程的学生(即学习了所有课程的学生)
select s#,sname from
s
where not exists
(select * from c where not exists(select * from sc where sc.s#=s.s# and sc.c#=c.c#))