22,210
社区成员
发帖
与我相关
我的任务
分享
declare @tb table(id int, result int)
insert @tb
select
1 , 1 union all select
1 , 2 union all select
2 , 2 union all select
3 , 3 union all select
4 , 1 union all select
4 ,2 union all select
4 ,3
declare @str varchar(10)
set @str='1,2'
select id from @tb
where charindex(','+ltrim(result)+',',','+@str+',')>0
group by id
having(count(*)>1) --这边是大于1
id
-----------
1
4
(2 行受影响)
declare @str varchar(10)
set @str='1,2'
select id from tb
where charindex(','+result+',',','+@str+',')>
group by id
having(count(*)>0)