MySQL LIKE 语句在除字符串开头之外的任何位置查找子字符串
我有一个 SQL 查询SELECT * FROM table WHERE column LIKE '%pdd%'
。
问题是我需要获取所有结果,不包括以“pdd”开头的结果,我的意思是找到“pdd”不开头的所有结果。怎么可能呢?
当“pdd”不在列的开头时,我确实需要匹配它。
I have a SQL query SELECT * FROM table WHERE column LIKE '%pdd%'
.
The problem is I need to get all results excluding those which start with "pdd", by which I mean find everything where "pdd" is not at the beginning. How could it be done?
I do need to match "pdd" when it is not at the beginning of the column.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我假设您的意思是与“pdd”匹配的所有行,除了“pdd”开头的行。
LIKE
谓词中的“_
”通配符表示“任意字符之一”,相当于正则表达式中的“.
”。I assume you mean all rows that match "pdd" except those where "pdd" is at the beginning.
The "
_
" wildcard inLIKE
predicates means "one of any character," equivalent to ".
" in regular expressions.如果我正确理解您的要求,您需要的是:
If I understand your requirement correctly what you need is:
您可以根据这些在表中出现的频率来优化查询。
You can optimise the query depending on how frequent these occurrences are in your table.
尝试:
Try: