如何检查子集
比如说我有子集 (111,112,113)
我要检查它在不在 select id from table where alive=1 里面
用 where (111,112,113) in (select id from table where alive=1)不起作用
问题点数:100、回复次数:5Top
1 楼hdhai9451(☆新人类☆)回复于 2006-03-11 08:02:51 得分 0
應該這樣寫:
select id from table where alive in(111,112,113)
Top
2 楼lsqkeke(可可)回复于 2006-03-11 08:05:43 得分 0
select 1 from table where alive=1 and id in(111,112,113)
如果返回1 说明在,如果返回为空 则表示在
Top
3 楼lsqkeke(可可)回复于 2006-03-11 08:15:21 得分 0
哦 理解有偏差! 对不起 :)
if exists(select 1 from table1 where alive=1 and id=111) and
exists(select 1 from table1 where alive=1 and id=112) and
exists(select 1 from table1 where alive=1 and id=113)
print '包含'
else
print '不包含'Top
4 楼RadishRabbitGao()回复于 2006-03-11 08:30:06 得分 0
一楼和二楼的没用
三楼是我现在用的,效率不高Top
5 楼lsqkeke(可可)回复于 2006-03-11 08:42:02 得分 100
如果用上面的,效率不高,可看看这样:
集合的包含关系,用另为个辅助表。
declare @t1 table (a int) --被包含的集合
insert @t1
select 111 union
select 112 union
select 113
--id 列必须为 int 类型
if exists(select 1 from @t1 where checksum(*) not in(select checksum(*)
from (select id from table1 where alive=1)t ))
print '包含'
else
print '不包含'Top




