表结构如下:id content includeid
1 aa 1,3,4
2 bb 2,3,5,6
3 cc 2,4,5,6,8,9
4 dd 1,3,4,6,7,8
找出所有includid 包含3 的select * from table where 3 in (includeid) 好像行不通啊? 谢谢
1 aa 1,3,4
2 bb 2,3,5,6
3 cc 2,4,5,6,8,9
4 dd 1,3,4,6,7,8
找出所有includid 包含3 的select * from table where 3 in (includeid) 好像行不通啊? 谢谢
create table test(id varchar(10),content varchar(10),incluedid varchar(200))
insert into test
select '1','aa','1,2,3'
union all select '2','bb','2,3,5,6'
union all select '3','cc','2,4,5,6,8,9'
union all select '4','dd','1,3,4,6,7,8'
union all select '5','ee','3,8,9,10'
union all select '6','ff','4,8,5,13,14'
union all select '7','gg','5,8,4,13'
--select * from test where CHARINDEX('3,',incluedid)>0 and charindex
select * from test where incluedid like '3,%' or incluedid like '%,3' or incluedid like '%,3,%'