like 也就是模糊查询 如:select * from user where user_name '%李%' locate 判断是否包含某字符串 如:select * from user wher
like 也就是模糊查询 如:select * from user where user_name '%李%'
locate 判断是否包含某字符串 如:select * from user where locate('李',user_name)>0
position 判断是否包含某字符串 如:select * from user where position('李' in user_name)>0
instr 判断是否包含某字符串 如:select * from user where instr(user_name,'李')>0
find_in_set 正好反过来,库里字段的值是否被包含在条件字符串里 如下:
select * from user where find_in_set (user_name,'李刚,刘备')>0
正则匹配两个字符串是否含有交集,我中有你,你中有我,如有共同部分,则返回数据,如下:
select * from user where user_name REGEXP REPLACE('李刚,刘备',',','|')
CONCAT(',',str,',') 查询某字段中以逗号分隔的字符串的方法,好处是如果是数字逗号拼接的话,查询的参数是个位数的话,很容易查询出一大堆覆盖个位数的多位数数字
select * from user where CONCAT(',','李刚,刘备',',') like '%,刘备,%'
来源地址:https://blog.csdn.net/cwzl_5203344/article/details/129244456
--结束END--
本文标题: mysql判断查询条件是否包含某字符串的7种方式
本文链接: https://www.lsjlt.com/news/391314.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0