当前位置:Gxlcms > 数据库问题 > MYSQL查询某字段中以逗号分隔的字符串的方法

MYSQL查询某字段中以逗号分隔的字符串的方法

时间:2021-07-01 10:21:17 帮助过:21人阅读


+----+-------+---------+
| id | pname | pnum    |
+----+-------+---------+
|  3 | 产品3 | 3,4     |
|  4 | 产品4 | 1,7,8,9 |
+----+-------+---------+
2 rows in set (0.01 sec)

 

 

3、select * from oa_student_archives where CONCAT(‘,‘,pe_projects,‘,‘) like ‘%,11,%‘;

这种方式也可以。

 

注意:

标红的mysql> SELECT * FROM test WHERE CONCAT(‘,‘,pnum,‘,‘) REGEXP ‘[^0-9]+[3|9][^0-9]+‘; 

这种,当时小于10的数据搜索是可以的,但是如果是大于10的,则不能用,原因我还不太清楚,有大神可以解释下吗?

 

总结如下:

1、select * from oa_student_archives where CONCAT(‘,‘,pe_projects,‘,‘) like ‘%,11,%‘;

2、select * from oa_student_archives where find_in_set(‘12‘, pe_projects);

 

以上的两个都可以用。

 

MYSQL查询某字段中以逗号分隔的字符串的方法

标签:tools   like   sdn   student   value   creat   insert   null   搜索   

人气教程排行