现有表:学生表:s(s#,sname)
课程表:c(c#,cname)
选课表:sc(s#,c#)
现要检索学习全部课程的学生名:
语句是:
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#))
为什么上面的语句可以实现上面的要求?理解万岁!
...全文
447打赏收藏
下面是高级程序员中的sql语句.大家帮忙理解以下!
现有表:学生表:s(s#,sname) 课程表:c(c#,cname) 选课表:sc(s#,c#) 现要检索学习全部课程的学生名: 语句是: 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#)) 为什么上面的语句可以实现上面的要求?理解万岁!
请楼主注明出处?????
1:select sname
2: from s
3: where not exists
4: (select *
5: from c
6: where not exists
7: (select *
8: from sc where sc.s#=s.s# and sc.C#=c.c#
9: )
10: )
我觉得有问题:
第二个子查询中:
7: (select *
8: from sc
where sc.s#=s.s# and sc.C#=c.c#
9: )
FROM句中只有SC,而在WHERE句中却用到了SC和S,难道它不知道SQL是先做子查询后做父查询的吗?????
嗯!
1:select sname
2: from s
3: where not exists
4: (select *
5: from c
6: where not exists
7: (select *
8: from sc where sc.s#=s.s# and sc.C#=c.c#
9: )
10: )
这样看:
7: 选出学习课程的所有SC.s#\SC.C#
6: 包含未修课程的SC.s#\SC.C#
3:除开已选出的其它项目