字段1  字段2   字段3  字段4      字段5                 字段6
1, 11, 白云, 2010,06, 4,7,6,9,10,5,0 6,6
1, 11, 白云, 2010,06, 4,7,9,10,1,0,6,6
1, 2, 白云, 2010,06, 4,7,6,9,1,0,1,1
学校1, 11, 白云, 2010,06, 14,15,17,6,9,10,13 39,39
学校1, 11, 白云, 2010,06, 4,7,6,9,10,2 39,39
学校1, 11, 白云, 2010,06, 4,7,5,6,1,2,6,6,9,10 39,39
学校1, 11, 白云, 2010,06, 4,7,5,6,1,2,6,14,15,17,6,9,10,6 39,39
学校1, 11, 白云, 2010,06, 5,7,6,9 39,39
select * from table1 where 字段5=变量 如:4怎么才能把字段5包含 4 的都找出啦

解决方案 »

  1.   

    select * from table1 where 字段5=like '%4%'
      

  2.   

    select * from table1 where 字段5 LIKE '%4%';
      

  3.   

    楼主去看下  % , _  在sql语句中的作用
      

  4.   

    select * from table1 where 字段5 like '%4%' ;
      

  5.   

    select * from table1 where 字段5 LIKE '%4%';
      

  6.   


    --这个sql有问题的,学校1, 11, 白云, 2010,06, 14,15,17,6,9,10,13 39,39 也会查出来
    --但是楼主好像不需要此条记录
    select * from table1 where 字段5 LIKE '%4%';--改为
    select * from table1 where ','||字段5','|| LIKE '%,4,%';
      

  7.   

    再完善下
    select * from table1 
     where 字段5 = '4'
        or 字段5 like '4,%'
        or 字段5 like '%,4,%'
        or 字段5 like '%,4';
      

  8.   

    select * from table1 where instr(字段5,'4')>0
      

  9.   


    再改改
    两边都加上分割符号','
    select * from table1 where instr(','||字段5||',',',4,')>0
      

  10.   


    --更正一下sql
    select * from table1 where ','||字段5||',' LIKE '%,4,%';
      

  11.   

    一个LIKE查询,大家整出这么多想法,妙啊!
      

  12.   

    select * from table1 where ','||字段5||',' like '%4%';
      

  13.   

    select * from table1 where 字段5=like '%4%'
      

  14.   

    直接等于4不就可以了,干嘛要写这么多like 啊?