select a.* from T a where exists(select 1 from T where C1=a.C1 and C2=2) and exists(select 1 from T where C1=a.C1 and C2=3)
楼上理解select distinct c1 from T a where C2=2 and exists(select 1 from T where C1=a.C1 and C2=3)
樓主是指這個? create table t (c1 varchar(02),c2 int) insert into t select 'a',1 union select 'a',2 union select 'b',1 union select 'b',2 union select 'b',3 union select 'c',2select c1 from T where c1 in (select c1 from T where c2=2) and c2=3 order by c1drop table t/*The result:*/c1 ---- b
from t
group by c1是不是这个?
a.*
from
T a
where
exists(select 1 from T where C1=a.C1 and C2=2)
and
exists(select 1 from T where C1=a.C1 and C2=3)
distinct c1
from
T a
where
C2=2
and
exists(select 1 from T where C1=a.C1 and C2=3)
create table t (c1 varchar(02),c2 int)
insert into t
select 'a',1
union
select 'a',2
union
select 'b',1
union
select 'b',2
union
select 'b',3
union
select 'c',2select c1 from T
where c1 in (select c1 from T where c2=2)
and c2=3
order by c1drop table t/*The result:*/c1
----
b