我现在有一张表记录是这样的:
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
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
REGEXP_LIKE(sort_id,'^2?')
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
.... WHERE REGEXP_LIKE(sort_id,'(^|,)'||'你要查找的数字'||'(,|$)');
我查询的条件
select * from tt
where length(replace(sort_id,','))<=2
and instr(sort_id,'22')>0
就不行了.
位数不能限定的吧
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