日期:2014-05-18  浏览次数:20601 次

sql问题:如何判断多个(个数不定)的ID值是否存在于同一个表中?
我需要对多个(个数不定)的ID值(这里,ID不是关键字段),是否存在于同一个表tableA中呢?

  这里的关键是我要判断的内容个数不同,但我知道是个集合。如ID值集合(2,4,6,9),判断这几个ID是否全在TableA中,全都在返回True,不全在(哪怕有一个不在)就返回false ????

------解决方案--------------------
declare @Count int
set @Count = 0
select @Count = Count(*)
from (
select ID from T
where ID in (2,4,6,9)
group by ID
)

if @Count = 4
begin
return true;
end
else
begin
return false;
end
------解决方案--------------------
select count(distinct *)
from tb where id in (2,4,6,9)