
1 mhycy 2014 年 12 月 16 日 字符串已知的话用IN ids IN ("5","2","3","6") |
2 Cynic222 2014 年 12 月 16 日 你这样用"like"等于用"=" |
3 l1905 2014 年 12 月 16 日 ids 字符串前后都加逗号, ids='1,2,3,4' => ids=',1,2,3,4,' 查询语句: ids like '%,5,%' or ids like '%,2,%' or ids like '%,3,%' or ids like '%,6,%' |
5 konakona 2014 年 12 月 16 日 比如你有一笔数据 $ids = '1,2,3,7,8,65,32,12,32,55' 你可以执行: select * from tablename where id in ('{$ids}'); //select * from tablename where id in('1,2,3,7,8,65,32,12,32,55'); |
6 s2555 OP 可能我表达还不清楚,是这样的: 表结构 id : 1 value:1,2,3,4 要用值=5,2,3,4 去把这个数据查询出来 难道select * from 表 where value in(5,2,3,4) 这样吗? |
10 holystrike 2014 年 12 月 16 日 把 5,2,3,6 拆成4个条件, 取 or 串在一起 select * from table where find_in_set(5, 字段名) OR find_in_set(2, 字段名) OR find_in_set(3, 字段名) OR find_in_set(6, 字段名) |
11 holystrike 2014 年 12 月 16 日 但是效率很低 如果可能的话,重新设计表吧 |
12 s2555 OP @holystrike 这样的话用 like 就可以啦,看来只能这样的了。谢谢大家 |
13 holystrike 2014 年 12 月 16 日 @s2555 like 不行吧,逗号怎么办? |