gpt4 book ai didi

mysql - 使用 SQL 来匹配查询字符串中的字符

转载 作者:行者123 更新时间:2023-11-30 00:02:55 32 4
gpt4 key购买 nike

我的问题是这样的;我在使用 sql 匹配查询的某些部分时遇到问题。例如我想要这样的声明:

 SELECT * FROM {table} WHERE {table}.title LIKE '%term%';

其中 term 是一些搜索词,table 是我正在查询的表。该语句几乎在所有情况下都适用。当查询项比数据库中的项长时,就会出现问题。例如:

  (assuming there is an entry in {table} with title="foobar")
SELECT * FROM {table} WHERE {table}.title LIKE '%foobars%';

由于 s,上面的内容不会匹配 foobars = foobar。

我可以用什么来克服这个问题?

谢谢。

最佳答案

在sql中,你可以执行'somestring' LIKE CONCAT('%',title,'%'),这是一个反向的类似语句,但你必须小心,因为性能相当慢。但对于您的问题,您应该尝试:

(assuming there is an entry in {table} with title="foobar")
SELECT * FROM {table} WHERE '%foobars%' LIKE CONCAT('%', {table}.title,'%');

关于mysql - 使用 SQL 来匹配查询字符串中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24869149/

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