您好,欢迎访问一九零五行业门户网

关于查询的一个有关问题

关于查询的一个问题
某表记录是这样的
id title cid
100 张三 2,3
101 李四 3,4
102 王五 12,13
如果搜索,条件是要查cid字段=2的记录
应该怎么写?
sql语句里的like应该不严谨,可能会把100和102这两条记录都查出来
------解决方案--------------------
sql codeselect * from table where find_in_set('2',cid);
------解决方案--------------------
mysql> select find_in_set(2, 2,3,4);
+-------------------------+
| find_in_set(2, 2,3,4) |
+-------------------------+
| 1 |
+-------------------------+
1 row in set (0.00 sec)
mysql> select find_in_set(2, 52,3,4);
+--------------------------+
| find_in_set(2, 52,3,4) |
+--------------------------+
| 0 |
+--------------------------+
1 row in set (0.00 sec)
mysql> select find_in_set(2, 2,3,4); 
+-------------------------+
| find_in_set(2, 2,3,4) |
+-------------------------+
| 1 |
+-------------------------+
1 row in set (0.00 sec)

其它类似信息

推荐信息