- 论坛徽章:
- 0
|
我现在正在学MySql,使用的书是李立功与赵扬编著的《MySQL程序设计与数据库管理》。现在非常困惑的是MySQL不支持子查询这一功能。我想向您请教一个问题:如何在MySQL的查询中描述“全部”这一属性。
--------------------------------------------------------------------------------
这里有一个具体的实例:SCS数据库中含有3个表:s(sno,sname,sage,
saddr),c(cno,cname,cteacher),sc(sno,cno,scgrade).其中各表的描述如下:s-学生,sno-学生编号,sname-学生姓名,sage-学生年龄,saddr-学生住址;c-课程,cno-课程编号,cname-课程名称,cteacher-教课的老师;sc-学生选课,sno-学生编号,cno-课程 编号,scgrade-该门课程的成绩。
--------------------------------------------------------------------------------
我想做这样的查询:1.学习了某老师讲授的全部课程的学生学号;2.未完全学习某老师讲授的全部课程的学生学号。就是说:假如一个叫“李明”的老师讲授了1,2,3,4共4门课程,有一些学生全部学习了这4门课程,而有一些学生只学习了其中的n门课程(n〈4)。我现在想要分别查询这两部分学生的学号。
--------------------------------------------------------------------------------
如果利用子查询,我的解决方法如下(在MS ACCESS中已运行通过):
1,select distinct sno
from sc sc1
where not exists(
select *
from c
where cteacher=" 李明” and not exists
(select *
from sc sc2
where sc1.sno=sc2.sno and sc2.cno=c.cno));
2,select distinct sno
from sc sc1
where cno=any(
select cno
from c
where cteacher=“李明”)
and exists(select *
from c
where cteacher=“李明” and not exists(
select *
from sc sc2
where sc1.sno=sc2.sno and sc2.cno=c.cno));
如果不用子查询,那么上面两个查询将怎样做出呢? |
|