select a.f from ##test a where exists (select f,c from ##test where f=a.f group by f,c HAVING COUNT(*)>1) group by a.f
create table ##test (F varchar(10), C varchar(10)) =========insert ##test select '001', '23' union all select '001', '24' union all select '001', '25' union all select '001', '24' union all select '001', '26' union all select '002', '23' union all select '002', '24' union all select '002', '25' union all select '003', '23' union all select '003', '24' …… select f,c from ##test group by f,c HAVING COUNT(*)>1 --结果: 001 24select a.f from ##test a where exists (select f,c from ##test where f=a.f group by f,c HAVING COUNT(*)>1) group by a.f---结果: 001
=========insert ##test
select '001', '23'
union all select '001', '24'
union all select '001', '25'
union all select '001', '24'
union all select '001', '26'
union all select '002', '23'
union all select '002', '24'
union all select '002', '25'
union all select '003', '23'
union all select '003', '24'
……
select f,c from ##test group by f,c HAVING COUNT(*)>1
--结果:
001 24select a.f from ##test a where exists (select f,c from ##test where f=a.f group by f,c HAVING COUNT(*)>1) group by a.f---结果:
001