表结构如下: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.   

    用 like把  select * from table where includeid like  '%3%'
      

  2.   

    不行啊,如果是有2位数的话 比如 1 like (11,13,14)那不就都列出来了啊?
      

  3.   

    select * from table where charindex(',3,',','+includeid+',')>0
      

  4.   

    select * from table where includeid like '%3%'
      

  5.   

    select * from table where CHARINDEX('3,',includeid+',')>0
      

  6.   

    不行啊,如果是有2位数的话  比如includeid = 11,13,14where includeid like '%1%' 那不就都列出来了啊?
      

  7.   

    select * from table where includeid like '3,%' or '%,3' or '%,3,%'
      

  8.   

    select * from table where includeid like '3,%' or includeid like '%,3' or includeid like '%,3,%'
      

  9.   

    drop table test
     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,%'