Mysql中的一个varchar字段被包含如(字段=河北条件是河北省)

re为位置的字段此处想匹配的是河北

方法一:

SELECT * FROM users WHERE find_in_set('河北省', re);

意思就是:mysql有很多字符串函数 find_in_set(str1,str2)函数是返回str2中str1所在的位置索引,str2必须以","分割开。

方法二:

使用locate(substr,str)函数,如果包含,返回>0的数,否则返回0 

我使用的方法二:SELECT * FROM t_weatherforecast  
WHERE   locate( '河北省',re)

猜你喜欢

转载自blog.csdn.net/microopithecus/article/details/85708370