让MySQL忽略“The”从 LIKE 条件开始?
我有一个公司名称列表,想要显示以某个字符开头的所有名称。例如d
。
所以查询是
SELECT * FROM company WHERE name LIKE 'd%'
但我也想要以“The”开头的公司所以
SELECT * FROM company WHERE name LIKE 'd%' OR name LIKE 'The d%'
但是现在当我们到达“t”时棘手的一点我想删除所有以“The”开头的公司 同时保留其他以“t”开头的内容(还保留诸如“The Truffle House”之类的内容,其中“The”后面的单词以“t”开头)。
有什么想法吗?想将逻辑保留在 MySQL 中......
I have a list of company names, and want to display all the names beginning with a certain character. d
for example.
So the query is
SELECT * FROM company WHERE name LIKE 'd%'
But I also want the companies that start with "The" so
SELECT * FROM company WHERE name LIKE 'd%' OR name LIKE 'The d%'
But now the tricky bit when we get to 't' I want to remove all those that start with 'The'
while keeping others that begin with a 't' (and also keeping anything like 'The Truffle House' where the word after 'The' begins with a 't').
Any ideas? Would like to keep the logic in MySQL...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
感谢您的回答,我刚刚
为
t
选择了这个,我刚刚做了一长串NOT LIKE
所以AND (company_name LIKE 'The%t ' 或者 company_name LIKE 't%') AND company_name NOT LIKE 'The a%' AND company_name NOT LIKE 'The b%'
等等...Thanks for the answers I've just opted for this
for
t
I've just done a long list ofNOT LIKE
soAND (company_name LIKE 'The%t' OR company_name LIKE 't%') AND company_name NOT LIKE 'The a%' AND company_name NOT LIKE 'The b%'
etc....