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)
这样也可以 select distinct M from bbb where N='x' and M in(select distinct M from bbb where N='Y')
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)
这样也可以
select distinct M from bbb where N='x' and M in(select distinct M from bbb where N='Y')