select a.* ,isnull(cnt,0) 子集数 from ta a left join (select col2,count(*) cnt from tb gruop by col2) b on a.col1=b.col2
select a.* from a where col1 in (select col2 from b)
select * from t1 a where exists(select 1 from t2 where id1=a.id1)
select count(*) from a where col1 in (select col2 from b)
declare @a table(id1 int,col1 varchar(10)) insert into @a select 1,'aa' union all select 2,'bb' union all select 3,'cc'declare @b table(id2 int,col2 varchar(10)) insert into @b select 1,'aa' union all select 2,'aa' union all select 3,'bb'select count(*) 记录数 from @a a where a.col1 in (select col2 from @b )
left join (select col2,count(*) cnt from tb gruop by col2) b
on a.col1=b.col2
select * from t1 a
where exists(select 1 from t2 where id1=a.id1)
insert into @a select 1,'aa'
union all
select 2,'bb'
union all
select 3,'cc'declare @b table(id2 int,col2 varchar(10))
insert into @b select 1,'aa'
union all
select 2,'aa'
union all
select 3,'bb'select count(*) 记录数
from @a a
where a.col1 in (select col2 from @b )