gpt4 book ai didi

mysql - 在mysql的CONCAT中添加通配符

转载 作者:行者123 更新时间:2023-11-29 11:08:35 25 4
gpt4 key购买 nike

我想搜索三个字段:id、名称和地址。我希望我的搜索有点智能。

订阅者表

id         |     firstname     |      lastname     |     address
N29-0001 | John | Doe | California
N29-0002 | Jonathan | Morson | Miami

到目前为止我的查询

select subscriberid, CONCAT(firstname," ",lastname) as fullname, address, city from subscriber where id like "%N29 Joh%" or CONCAT(firstname," ",lastname) like "%N29 Joh%" or address like "%N29 Joh%" or city like "%N29 Joh%"

我希望我的查询能够搜索,如果我输入 N29 Joh,它将搜索 John Doe。

最佳答案

您可能需要全文索引。但是,如果您想要匹配任何单词并且不关心性能,则可以使用正则表达式:

select subscriberid, CONCAT(firstname, ' ', lastname) as fullname,
address, city
from subscriber
where subscriberid regexp 'N29|Joh' or
concat(firstname, ' ', lastname) like 'N29|Joh' or
address like 'N29|Joh' or
city like 'N29|Joh';

关于mysql - 在mysql的CONCAT中添加通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com