select id1 from table2 where charindex(','+convert(varchar(10),id2)+',',','+id2s+',')>0 and flag =0
id2s 是列id2的一个集合串:'1,2,3',表示id2为1、2、3的行 要求先找出id2s对应的所有的distinct id1 然后从这些id1中找出 not exists (select 1 from table2 where flag=1 and id1=@id1)的所有id1
id2s 是列id2的一个集合串:'1,2,3',表示id2为1、2、3的行 要求先从table2找出id2s对应的所有的distinct id1 然后从这些id1中找出 对于每个id1:@id1,找出 not exists (select 1 from table2 where flag=1 and id1=@id1)的所有id1不知表述清楚没有
declare @id2s varchar(100) set @id2s='1,2,3' select distinct id1 from table2 where charindex(','+convert(varchar,id2)+',',','+@id2s+',')>0 and flag=0
select id1 from table2
where charindex(','+convert(varchar(10),id2)+',',','+id2s+',')>0
and flag =0
要求先找出id2s对应的所有的distinct id1
然后从这些id1中找出 not exists (select 1 from table2 where flag=1 and id1=@id1)的所有id1
要求先从table2找出id2s对应的所有的distinct id1
然后从这些id1中找出
对于每个id1:@id1,找出 not exists (select 1 from table2 where flag=1 and id1=@id1)的所有id1不知表述清楚没有
set @id2s='1,2,3'
select distinct id1 from table2
where charindex(','+convert(varchar,id2)+',',','+@id2s+',')>0
and
flag=0