我现在有一张表记录是这样的:
id  title  sort_id
1   aaa    2,4
2   bbb    3
3   ccc    2,3
4   ddd    22,3
其中sort_id是对应sort表的
我现在知道sort_id查询出上表中出现这个id的记录:
sort_id为2时查出
1   aaa    2,4
3   ccc    2,3各路高手支支招,,帮写条查询的sql

解决方案 »

  1.   

    sos...
      

  2.   

    10G可以用正则表达式
    REGEXP_LIKE(sort_id,'^2?')
      

  3.   

    这样查不行呀.查2的时候会把21 22都查出来了,用like不行
      

  4.   


    1 aaa 2,4
    2 bbb 3
    3 ccc 2,3
    4 ddd 22,3
    5 eee 2
    6 fff 222,5
    7 ggg 2222,5SQL:select * from tt 
    where length(replace(sort_id,','))<=2
    and instr(sort_id,'2')>0RESULT:1 aaa 2,4
    3 ccc 2,3
    5 eee 2
      

  5.   


    .... WHERE REGEXP_LIKE(sort_id,'(^|,)'||'你要查找的数字'||'(,|$)');
      

  6.   


    我查询的条件
    select * from tt 
    where length(replace(sort_id,','))<=2
    and instr(sort_id,'22')>0
    就不行了.
    位数不能限定的吧
      

  7.   

    不用长度限制,用位置限制好了1 aaa 2,4
    2 bbb 3
    3 ccc 2,3
    4 ddd 22,3
    5 eee 2
    6 fff 2,5
    7 ggg 2,25
    8 hhh 4,2select *  from tt 
    where 
     instr(replace(sort_id,','),'2')=1
     and instr(replace(sort_id,','),'2',2,1)=01 aaa 2,4
    3 ccc 2,3
    5 eee 2
    6 fff 2,5