让MySQL忽略“The”从 LIKE 条件开始?

发布于 2024-10-11 18:51:46 字数 410 浏览 5 评论 0原文

我有一个公司名称列表,想要显示以某个字符开头的所有名称。例如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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡淡離愁欲言轉身 2024-10-18 18:51:47
SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'
SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'
昵称有卵用 2024-10-18 18:51:47

尝试:

SELECT * FROM company WHERE name regexp '^(The)d'

Try:

SELECT * FROM company WHERE name regexp '^(The)d'
浪漫之都 2024-10-18 18:51:47

感谢您的回答,我刚刚

SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'

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

SELECT  *
FROM    company
WHERE   (name LIKE '?%' AND NOT name LIKE 'The %')
        OR name LIKE 'The ?%'

for t I've just done a long list of NOT LIKE so

AND (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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文