要求:
求A.NAME,满足条件
A.NEME=B.NAME
B.ID=C.ID
C.NEW='E' 并且COUNT(*)=2结果:NEME
--------------
AAA
DDD
==========================================================================================
表A:NAME
-------------------------
AAA
BBB
CCC
DDD==========================================================================================表B:ID NAME
-----------------------------------
111 AAA  
222 BBB
333 CCC
444 DDD
==========================================================================================
表CID      |     CLASS     |    NEW
-----------------------------------
111     |      I        |     E
111     |      T        |     T
111     |      O        |     E
222     |      I        |     E
222     |      O        |     E
333     |      T        |     T
333     |      O        |     E
444     |      T        |     T
        |               |

解决方案 »

  1.   

    select A.NAME
    from a , b , c 
    where
    A.NEME=B.NAME and
    B.ID=C.ID and
    C.NEW='E'  
    group by a.name having count(1) = 2
      

  2.   

    要表C中,每组值有2个‘E’的,取出A表名称
      

  3.   

      表C中ID为444时,没有2个E啊?怎么也查出来了? 数据不全?
      

  4.   

    按照你说的取出来的应该是AAA,BBB啊
    with a as(
    select 'AAA' NAME from dual
    union all
    select 'BBB' from dual
    union all
    select 'CCC' from dual
    union all
    select 'DDD' from dual),
    b as(
    select 111 ID,'AAA' NAME from dual
    union all
    select 222,'BBB' from dual
    union all
    select 333,'CCC' from dual
    union all
    select 444,'DDD' from dual),
    c as(
    select 111 ID ,'I' CLASS,'E' NEW from dual
    union all
    select 111,'T','T' from dual
    union all
    select 111,'O','E' from dual
    union all
    select 222,'I','E' from dual
    union all
    select 222,'O','E' from dual
    union all
    select 333,'T','T' from dual
    union all
    select 333,'O','E' from dual
    union all
    select 444,'T','T' from dual)
    select a.name from a,b,c
    where a.name=b.name and b.id=c.id
    and c.new='E'
    group by a.name
    having count(*)=2NAM
    ---
    BBB
    AAA
      

  5.   


    select A.NAME from a,b
    where a.name=b.name and
    exists
       (select 1 from c
         where b.id=c.id and c.new='E'
         group by c.id
         having count(id)=2)
      

  6.   

    结果:NEME
    --------------
    AAA
    BBB