有一个表:table
字段为:shopid,range
要求匹配与shopid= 'mlg '所对应的range有重叠range值的相应shopid
(模糊匹配)
------解决方案--------------------
create table T(shopid varchar(20), range varchar(20))
insert t select 'mlg ', '抗丁大楼 '
union all select 'mlg ', '河北大厦 '
union all select 'guibin ', '河北 '
union all select 'jiangsu ', '南京大厦 '
union all select 'dayong ', '抗丁大楼 '
select * from T as tmp
where exists
(
select 1
from T
where shopid= 'mlg ' and charindex(tmp.range, range)> 0
) and shopid <> 'mlg '
--result
shopid range
-------------------- --------------------
guibin 河北
dayong 抗丁大楼
(2 row(s) affected)