简体   繁体   English

使用regexp从mysql查询中排除结果

[英]Exclude results from a mysql query using regexp

I got a table with the following values 我得到了一个具有以下值的表

titles:
Accountant
Auditor
Bookkeper
Forensic Accountant
Tax Accountant

I'd like to select all the titles that don't contain "Accountant" in it, i'm currently trying with 我想选择所有不包含“会计”的标题,我目前正在尝试

SELECT * FROM careers WHERE title NOT REGEXP '^Accountant'

But it still selects "Forensic Accountant" and "Tax Accountant" 但是它仍然选择“法务会计师”和“税收会计师”

Any thoughts? 有什么想法吗?

Thanks in advance! 提前致谢!

use not like instead of regexp: 使用not like代替regexp:

SELECT * FROM careers WHERE title NOT LIKE '%Accountant%'

See the SQLFiddle 参见SQLFiddle

The regex is wrong, you are using the caret(^) , which means the words you are excluding should start with Accountant, instead remove the caret and you should be good 正则表达式是错误的,您使用的是插入符号(^),这意味着您要排除的单词应以Accountant开头,而应删除插入符号,您应该会

SELECT * FROM careers WHERE title NOT REGEXP 'Accountant'

To exclude something user defined, based on what jobtitle is selected, do something like the following 要基于选择的职位,排除用户定义的内容,请执行以下操作

SELECT * FROM careers WHERE title NOT REGEXP (SELECT regexMatch FROM careers WHERE title = "Tax Accountant")

您可以像这样使用LIKE代替REGEXP:

SELECT * FROM careers WHERE title NOT LIKE '%Accountant%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM