当前位置: 代码迷 >> Sql Server >> sql有关问题:怎么判断多个(个数不定)的ID值是否存在于同一个表中
  详细解决方案

sql有关问题:怎么判断多个(个数不定)的ID值是否存在于同一个表中

热度:39   发布时间:2016-04-27 13:14:01.0
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)
  相关解决方案