SELECT name from tb where col in(1,2) group by name having count(distinct col) = 2
or:SELECT name from tb a where col =1 and exists ( select 1 from tb where name = a.name and col = 2 )or:SELECT distinct a.name from tb a,tb b where a.col =1 and b.name = a.name and b.col = 2
select name from tb where col betwen 1 and 2; --between包括临界么? SELECT name from tb where col in(1,2);
declare @str varchar(30)='1,2' select name from tb a where (select rtrim(col)+',' from tb where name=a.name for xml path(''))=@str+','
from tb where col in(1,2)
group by name
having count(distinct col) = 2
from tb a
where col =1
and exists (
select 1 from tb
where name = a.name
and col = 2
)or:SELECT distinct a.name
from tb a,tb b
where a.col =1
and b.name = a.name
and b.col = 2
SELECT name from tb where col in(1,2);
select name from tb a
where (select rtrim(col)+',' from tb where name=a.name for xml path(''))=@str+','