【问题标题】:How to use contains and like in one SQL query如何在一个 SQL 查询中使用 contains 和 like
【发布时间】:2013-10-18 00:33:33
【问题描述】:

我希望在一个 sql server 查询中使用 'contains' 和 'like',如下所示:

select *
from product
where 
contains(product.title, '"*grand theft auto 5 (inkl. A*"')
or product.title like 'grand theft auto 5 (inkl. A%'

但似乎这不一起工作,没有错误但sql server不会结束请求。

这行得通:

select *
from product
where 
contains(product.title, '"*grand theft auto 5 (inkl. A*"')

这也有效

select *
from product
where 
product.title like 'grand theft auto 5 (inkl. A%'

结合这一点,我的想法是我找不到产品,因为 '.一个'

我认为'.'是一个停用词,但如果我可以将它与 like 结合起来,就会解决问题。

有什么帮助吗? 非常感谢

【问题讨论】:

    标签: sql sql-server contains sql-like


    【解决方案1】:

    尝试将contains 替换为freetext 并去掉搜索字符串中的双引号和星号:

    select *
    from product
    where freetext(product.title, 'grand theft auto 5 (inkl. A')
    

    【讨论】:

    • 这将返回很多包含其中一个单词的结果。它应该得到确切的字符串包含
    • 好的。您可以离开contains,但从搜索字符串中删除干扰词并将其划分为单独的词:where contains(product.title, '"grand" & "theft" & "auto" & "5" & "inkl"')。并且仅在使用like 的切片结果集之后。
    猜你喜欢
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2012-01-08
    • 2015-09-29
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多