偶现在有一个表如下room sd
j101 a
j101 b
j102 a
j102 b
j103 b
j104 c
j104 a我现在要选出所有SD=A AND SD=B 的ROOM
我要的结果如:
ROOM
J101
J102请问要如何写,谢谢

解决方案 »

  1.   


    select room from 
    (select * from table where sd = a or sd = b)
    group by room having count(1) = 2
      

  2.   

    Select * from TableName A 
    Where Exists (Select 1 from TableName Where sd='B' And room=A.room) And  sd='A'
      

  3.   

    --修改一下
    select distinct room from 
    (select * from table where sd = a or sd = b)
    group by room having count(1) = 2
      

  4.   

    Select A.room from TableName A 
    Inner Join  TableName B 
    On A.room=B.room
    Where A.sd='A'  And B.sd='B'
      

  5.   

    declare @t table(room varchar(10),sd varchar(10))
    insert into @t
    select 'j101', 'a'
    union all select 'j101', 'b'
    union all select 'j102', 'a'
    union all select 'j102', 'b'
    union all select 'j103', 'b'
    union all select 'j104', 'c'
    union all select 'j104', 'a'select room from @t where sd in('a','b') group by room having count(1)>1
      

  6.   

    paoluo(一天到晚游泳的鱼) 弓虽  阿!