问题:
查询选修了4门以上的课程的学生学号及姓名.
有两个表:student和grade;
分别为:请问查询语句?
最好能讲详细点.谢谢.

解决方案 »

  1.   

    抱歉,那个图片太小;
    问题:
    查询选修了4门以上的课程的学生学号及姓名.
    有两个表:student和grade
    分别为:
      

  2.   

    select
       a.sno,a.name
    from
       student a,grade b
    where
       a.sno=b.sno
    and
       b.cno in(select cno from grade group by cno having count(1)>=4)
     
      

  3.   

    我解释一下吧,grade表中的cno是选修的课程号
      

  4.   

    小F,不用B表吧,FROM 后面
      

  5.   

    select
       a.sno,a.name
    from
       student a,grade b
    where
       a.sno=b.sno
    and
       (select count(1) from grade where cno sno=a.sno)>=4
      

  6.   

    select
       a.sno,a.name
    from
       student a,grade b
    where
       a.sno=b.sno
    and
       (select count(1) from grade where cno sno=b.sno)>=4
      

  7.   

    student和grade
    select
       a.sno,a.name
    from
       student a
    where
       a.sno in(select sno from grade group by sno having count(1)>=4)
      

  8.   

    select
      a.sno,a.name
    from
      student a
    where
      a.sno in(select sno from grade group by sno having count(1)>=4)
      

  9.   

    --难道是这样?
    select
       a.sno,a.name
    from
       student a,grade b
    where
       a.sno=b.sno
    and
       b.sno in(select sno from grade group by sno having count(1)>=4)
      

  10.   

    10楼正解,但是为什么是count(1),1是什么意思啊?为什么放在count中啊?