select distinct M
from tablename
where N='x' and M in ( select M from tablename where N='Y')

解决方案 »

  1.   

    declare @ table(M char(1),N char(1))
    insert @ select 
    'a', 'x' union all select 
    'a', 'y' union all select 
    'a', 'z' union all select 
    'b' ,'x' union all select 
    'b', 'y' union all select 
    'c', 'x'
    select a.M from 
    (
    select distinct M from @ where N='x'
     )a
    ,
    (
    select distinct M from @ where N='y'
    )b
    where a.M=b.M--测试结果M    
    ---- 
    a
    b(2 row(s) affected)
      

  2.   


    这样也可以
    select distinct M from bbb where N='x' and M in(select distinct M from bbb where N='Y')
      

  3.   

    谢过victorycyz(中海), LoveSQL(GG), shuichangliu三位老大,又快又好!!!谢谢!!!