09:20:11 SQL> select * from sc;S#         C#              GRADE
---------- ---------- ----------
001        A                  80
001        B                  90
001        C                  78
002        C                  76
003        A                  80
003        B                  90
004        A                  80
004        B                  89
004        C                  90已选择9行。已用时间:  00: 00: 00.47
09:20:22 SQL> select s# from sc where c# in (select c# from sc where s#='003')
09:20:29   2  and s#<>'003' group by s#
09:20:31   3  having count(*)=(select count(*) from sc where s#='003');S#
----------
001
004已用时间:  00: 00: 00.31
09:20:31 SQL>

解决方案 »

  1.   

    bzszp(SongZip) 的思路很巧妙,支持!!
      

  2.   

    09:48:50 SQL> select s# from sc where c# in (select c# from sc,s where sc.s#=s.s# and sname='S3')
    09:49:21   2  and s#<>(select s# from s where sname='S3')
    09:49:46   3  group by s#
    09:49:49   4  having count(*)=(select count(*) from sc,s where sc.s#=s.s# and sname='S3');S#
    ----------
    001
    004已用时间:  00: 00: 00.15
    09:49:49 SQL>
      

  3.   

    select s# from sc where c# in (select c# from sc where s#=(select s# from s where sname='s3'))
      and s#<>(select s# from s where sname='s3') 
      group by s#
     having count(*)=(select count(*) from sc where s#=(select s# from s where sname='s3') );
      

  4.   

    bzszp思路巧妙,不过如果出现: 001 A 80
                                 001 A 90
    的话,就会有点问题,也许一门课出现两个成绩不可能
      

  5.   

    谁能告诉我怎么发贴?????????????紧急求助,!!!!!!!!!!!!!!!!!!!#15
    有一个ORACLE购买问题   谁知道按用户数买和按PROCESSER买LICENSE差异到底如何,谁能给我解饰一下??????????????????????????急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  6.   

    楼上的,你到小的论坛里就可以 发了,不要到整个oracle目录下,点击左上角上的《显示导航栏]就进入oracle的小类社区就可以了!
      

  7.   

    bzszp(SongZip)的答案很巧妙,最妙的是最后一句,解决了问题~~
      

  8.   

    可能还有别的方法,但是 bzszp(SongZip)的是对的
      

  9.   

    是不是应该把count(*)=改成count(*)>=呢?
      

  10.   

    用exists也可以实现,不过不易读。我记得数据库的教科书上有一个和楼主一样的例子,用exists写的,实现的逻辑比楼主的还要复杂
      

  11.   

    select s#
      from sc
     where exists (select 1
              from sc sc1
             where sc1.s# = (select s# from s where sname = 'S3') and
                   sc.c# = sc1.c#) and
           s# != (select s# from s where sname = 'S3')
     group by s#
    having(count(distinct c#) >= (select count(distinct c#)
                                    from sc
                                   where s# =
                                         (select s# from s where sname = 'S3')))不知道有没有重复的情况,我加了distinct
    flamingo100不用>=,自己再想想
      

  12.   

    >=是不对,
    但题目要求的是包含s3所学的课程,而不是和他一样的呀。。
      

  13.   

    to flamingo100exists (select 1
              from sc sc1
             where sc1.s# = (select s# from s where sname = 'S3') and
                   sc.c# = sc1.c#) and
           s# != (select s# from s where sname = 'S3')上面语句段限定只统计某学生包含S3学生所学课程数