日期:2014-05-18 浏览次数:20478 次
--> 测试数据: @表A declare @表A table (a1 int,a2 int,a3 int) insert into @表A select 5,9,7 union all select 1,3,4 union all select 2,6,1 declare @s varchar(10) set @s='1,5,8' select a1,count(1) as cnt from ( select a1 from @表A union all select a2 from @表A union all select a3 from @表A ) a where charindex(','+ltrim(a1)+',',','+@s+',')>0 group by a1 /* a1 cnt ----------- ----------- 1 2 5 1 */