sishui
路人甲
路人甲
  • 注册日期2007-10-04
  • 发帖数35
  • QQ
  • 铜币59枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2278回复:1

SQL求救!!

楼主#
更多 发布于:2007-12-20 15:45
<DIV>
<P align=left>检索全部学生都选修的课程号与课程名。</P>
<P align=left></P>
<P align=left>学生S(SN,SNAME)</P>
<P align=left></P>
<P align=left>选课SC(SN,CN,GRADE)</P>
<P align=left></P>
<P align=left>课程C(CN,CNAME,TEACHER)</P></DIV>
<DIV></DIV>
<DIV>
<DIV></DIV>
<DIV>select CN,CNAME  from C<br> where not exists <br>
<P align=left>    (<br>   select * from S<br>   where not exists </P>
<P align=left>(<br>select * from SC<br>where SC.SN=S. SN and SC.CN= C.CN<br>   )  </P>
<P align=left>)</P>
<P align=left></P>
<P align=left>这个过程是怎样执行的?对这个意思 大概知道,因为SQL中没有全程量词,所以翻译成,对于这样的课程,没有一个学生不选. 麻烦详细说明,我只知道一个EXISTS 的用法.多了就不知道了?</P>
<P align=left></P>
<P align=left>谢谢了!!!</P></DIV></DIV>
[此贴子已经被作者于2007-12-21 21:26:45编辑过]
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2007-12-24 16:12
<P>题目: A. 对于教学数据库存的三个基本表: <BR>S(S#,SNAME,AGE,SEX) <BR>SC(S#,C#,GRADE) <BR>C(C#,CNAME,TEACHER) <BR>试用SQL的查询语句表达下列查询: <BR>1.检索LIU老师所授课程的课程号和课程号. <BR>2.检索年龄大于23岁的男学生的学号和姓名. <BR>3.检索学号为S3学生所学课程的课程名与任课教师名. <BR>4.检索至少选修LIU老师所授课程中一门课程的女学生姓名. <BR>5.检索WANG同学不学的课程的课程号. <BR>6.检索至少选修两门课程的学生学号. <BR>7.检索全部学生都选修的课程的课程号与课程名. <BR>8.检索选修课程包含LIU老师所授课程的学生学号.</P>

<P>1.select c#,cname from c where teacher='liu' <BR>2.select s#,sname from s where age>23 and sex='男' <BR>3.select cname,teacher from sc,c where sc.c#=c.c# and s#='s3' <BR>4.select distinct sname from s,sc,c where s.s#=sc.s# and c.c#=sc.c# and teacher='liu' <BR>5.select c# from c where not in (select c# from sc where s#=(select s# from s where sname='wang')) <BR>6.select s# from s,sc where s.s#=sc.s# group by s# having count(c#)>=2 <BR>7.select c#,cname from c where c# in (select c# from sc as sc1 where sc1.s# not in (select s.s# from sc as sc2 ,s where not exists (select * from s ,sc as sc3 where sc3.c#=sc2.c# and sc3.s#=s.s#))) <BR>8.Select s# from sc sc1 where c# in <BR>(select c# from sc as sc2 where not exists (select * from c where teacher='liu' and not exists( select * from sc as sc3 where sc3.s#=sc2.s# and sc3.c#=c.c#)))</CA></CD></P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部