有三张表
students                           
sid    sname    age   sex
100    am      23   b
111    bm      23   b
122   pom      22   g
133   mk       20   b
course
cid       cname     
900      java
911      c
922      c++
933      d
944      dota
955      war3sc
sid      cid     cj
100      900     89
100      911     80
111      955     90
111      933     77
111      944     88
111      911     90
111      900     99  
122      933     100
   
通过这张表差出选修课程是5门的学生的id和name
这怎么做啊 高手教教我啊
      

解决方案 »

  1.   

    select sid,sname
    from students inner join(
          select sid,count(cid) t_cid from sc
          group by sid
    ) A on students.sid = A.sid and A.t_cid = 5我也是刚学习 sql ,你看一下,这样是你要的意思吗
      

  2.   


    select sid,sname from students t,
    (select sid,count(distinct cid) from sc group by sid having count(distinct cid)=5) t1 where t.sid=t1.sid
      

  3.   

    楼主我估计真要有war3和dota这两门课的话,你肯定能拿奖学金哈哈!这么简单你都不写,玩dota太多了哈
    select sid, sname
      from students s, (select sid, count(cid) cu group by sid from sc) t
     where s.sid = t.sid
       and t.cu = 5
      

  4.   

    笔误不好意思!select s.sid, sname
      from students s, (select sid, count(cid) cu  from sc group by sid) t
     where s.sid = t.sid
       and t.cu = 5
      

  5.   

    6楼的答案经过验证是正确的,不过偶是这样写的:
    select sid,sname from students where sid in(select sid from sc  group by sid having count(*)=5)
      

  6.   

    LS正解select sid,sname from students where sid in(select sid from sc  group by sid having count(*)=5)不过感觉你的sc表有必要加一个id当主键
    你这个现在只可能有复合主键了