日期:2014-05-18 浏览次数:20562 次
declare @a表 table (id int,col2 int,col3 int,col4 int) insert into @a表 select 1,1,7,2 union all select 2,2,4,1 union all select 3,2,4,1 declare @b表 table (id int,col2 int,col3 int,col4 int) insert into @b表 select 1,2,4,1 union all select 2,3,4,2 union all select 3,1,7,9 select distinct col2,col3,col4, 表内重复行数=(select count(1)-1 from @a表 where a.col2=col2 and a.col3=col3 and a.col4=col4), 表外重复行数=(select count(1) from @b表 where a.col2=col2 and a.col3=col3 and a.col4=col4) from @a表 a where (select count(1)-1 from @a表 where a.col2=col2 and a.col3=col3 and a.col4=col4)>0 or (select count(1) from @b表 where a.col2=col2 and a.col3=col3 and a.col4=col4)>0 /* col2 col3 col4 表内重复行数 表外重复行数 ----------- ----------- ----------- ----------- ----------- 2 4 1 1 1 */