【问题标题】:Best way to compare one column value with the words contained in the other column将一列值与另一列中包含的单词进行比较的最佳方法
【发布时间】:2013-04-19 12:44:38
【问题描述】:

我的表结构如下所示。

Products { product_name, brand, model}

都是varchar字段(字段比较多但和我的问题无关。这个表有将近5000000个。

现在我需要做的是,我想遍历所有产品并检查product_name是否包含任何其他产品品牌和型号(不是单词的一部分而是完整的单词,所以产品名称应该包含一个单词的型号和一个单词的品牌),如果是这样,请将它们存储在相同产品的某个地方。

我已经使用相关子查询方法研究了全文索引,但后来知道 CONTAINS 函数不接受列名作为第二个单词,我也不知道如果以某种方式实现了它会有多快。

任何关于这样做的建议都会对我很有帮助。

非常感谢您的帮助。

【问题讨论】:

    标签: sql sql-server sql-server-2008 full-text-search


    【解决方案1】:

    like 和 exists 不能做到这一点吗?

    select * from Products p
    where exists(select * from Products 
                 where p.product_name != product_name 
                 and (' ' + p.product_name + ' ' like '% ' + brand + ' % ' + model + ' %'
                    or ' ' + p.product_name + ' ' like '% ' + model + ' % ' + brand + ' %'))
    

    【讨论】:

    • 感谢 @muhmud 带来的东西,功能上是的,这对我来说有点用,但考虑到我必须处理的记录数量,这非常慢,这需要很长时间。
    • 这是一次性的,还是需要定期进行?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多