一个学生表(学号,姓名,性别,专业,出生日期),一个课程表(课程号,课程名),一个学生课程表(字段学号,课程号,成绩),求至少选修了学号是1042的学生所选修的全部课程的学生学号和姓名

解决方案 »

  1.   

    select distinct b.学号,a.姓名 
    from 学生表 a,学生课程表 b 
    where a.学号=b.学号 
    and b.课程号 in (select 课程号 from 学生课程表 where 学号='1042'); 
      

  2.   

    给楼主一个思路:
    即是求,不存在这样的课程,学号为1042的选修了y,而学生x没有选。
    用双重not exist去实现就行了。BTW,我记得王珊那本教材里头就有这样的例子,在第三版第三章(数据查询)
      

  3.   

    ACMAIN_CHM大哥推荐的那边《数据库系统》第二版里面就有这样的题目,看起来好熟悉啊。
      

  4.   


    select studentid,studentname from studenttb,studentcoursetb
     where studenttb.studentid=studentcoursetb.studentid
     and  courseid in (select courseid from studentcoursetb where studentid=1024