简体   繁体   English

SQL查询,用于解析文本主体以从列表中提取字符串

[英]SQL query for parsing a body of text to extract a string from a list

I need help on an SQL query to perform the following: 我需要有关SQL查询的帮助来执行以下操作:

I have a table with a list of possible string values for products. 我有一张表,其中列出了产品的可能字符串值。

I have a second table with free form text in which this product may be mentioned. 我还有第二张桌子,上面有自由格式的文字,可能会提到该产品。 Is there any way an SQL query can extract the string if it is present in the 1st table? 如果第一个表中存在字符串,SQL查询有什么方法可以提取字符串?

I read on another SO post about CHARINDEX and SUBSTRING. 我在另一篇关于CHARINDEX和SUBSTRING的文章中读到。 Will this be efficient in this scenario? 在这种情况下这会有效吗? How can i apply this in my use case? 我该如何在用例中应用它?

AN example for my scenario is this: 我的情况的一个示例是:

My table, PRODUCTS, has the following format, 我的表格PRODUCTS具有以下格式,

Product
 XXX
 YYY
 ZZZ
 DDD

The other table has a column in which there is large amount of text in which this product will be mentioned. 另一个表有一列,其中有大量文本将提及此产品。 Like: 喜欢:

Record Number    User Review

      1           I like XXX for its versatility but YYY is better. 
      2           XXX is a horrible product. DO not buy.
      3           YYY and DDD are best in class. Many do not know how to use it.

Now I want to extract the product names using a query in this manner. 现在,我想以这种方式使用查询来提取产品名称。

Record Number    Product in Review
      1                XXX
      1                YYY
      2                XXX
      3                YYY
      3                DDD 

Thank you in advance for your time and help. 预先感谢您的时间和帮助。

This should work but it will be slow on big tables: 这应该可以,但是在大表上会很慢:

Select p.id, f.id, p.name from product
Inner Join freeform f on f.text like '%'+p.name+'%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM