在字符串中搜索多个关键字值
Search multiple keyword values in a string
我有一个 table 的名字 keywordsTable
,我需要 select 关键字并需要找到计数,它们在另一个 [=29= 中被提及的次数] 名为 dataTable
。
这是 keywordsTable
的一些虚拟数据:
id userId context keywords
-----------------------------------------
1 admin Hair Products Shampoo
2 admin Hair Products Hair Conditionar
3 admin Agriculture Wheat
4 admin Hair Products Minoxidil
这里是 dataTable
的一些虚拟数据
id data
------------
1 No matter the event, Sunsilk Black Shine Shampoo with Amla Pearls helps your hair shine upto 24 hrs. So even in heat and sweat it gives your hair upto 24 hrs shine!
2 Choose Head & Shoulders and dandruff will never be a problem again
3 Amazing hair recovery with minoxidil
4 Expansion of agriculture is reducing forest areas
这是我目前为止尝试过的方法。
drop table if exists #searchKeywords
select keywords
into #searchKeywords
from keywordTable
where context = 'Hair Products' and userId= 'admin'
select *
from #searchKeywords
select count(*)
from dataTable
where data like ((Select '%'+keywords+'%' from #searchKeywords))
但是我收到这个错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
like
运算符无法按照您尝试使用的方式工作。而是尝试 join
例如
select count(*)
from dataTable T
inner join #searchKeywords K on T.[data] like '%' + K.keywords + '%'
我有一个 table 的名字 keywordsTable
,我需要 select 关键字并需要找到计数,它们在另一个 [=29= 中被提及的次数] 名为 dataTable
。
这是 keywordsTable
的一些虚拟数据:
id userId context keywords
-----------------------------------------
1 admin Hair Products Shampoo
2 admin Hair Products Hair Conditionar
3 admin Agriculture Wheat
4 admin Hair Products Minoxidil
这里是 dataTable
id data
------------
1 No matter the event, Sunsilk Black Shine Shampoo with Amla Pearls helps your hair shine upto 24 hrs. So even in heat and sweat it gives your hair upto 24 hrs shine!
2 Choose Head & Shoulders and dandruff will never be a problem again
3 Amazing hair recovery with minoxidil
4 Expansion of agriculture is reducing forest areas
这是我目前为止尝试过的方法。
drop table if exists #searchKeywords
select keywords
into #searchKeywords
from keywordTable
where context = 'Hair Products' and userId= 'admin'
select *
from #searchKeywords
select count(*)
from dataTable
where data like ((Select '%'+keywords+'%' from #searchKeywords))
但是我收到这个错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
like
运算符无法按照您尝试使用的方式工作。而是尝试 join
例如
select count(*)
from dataTable T
inner join #searchKeywords K on T.[data] like '%' + K.keywords + '%'