日期:2014-05-18  浏览次数:20393 次

统计关键词在新闻纪录出现的次数
表1 TradeKeywords
Keyword Amount ...

表2 News
NewsId Title Content ...

需求是统计TradeKeywords表里Keyword在新闻表里出现的次数,单个词 SELECT COUNT(0) FROM News WHERE Title LIKE '%防盗门%',表循环就不会了,还有就是如何更新得到的统计次数到Amount字段中

------解决方案--------------------
select sum(case when charindex('关键词',News)>0 then 1 else 0 end) as 次数 from News
------解决方案--------------------
创建全文索引,使用containtable亦可。


------解决方案--------------------
楼主问题不明确,
如果关键词在一个新闻中出现了多次,这个要不要算在出现的记录次数里面,如果这个要计算,那就很麻烦了。如果不算,那简单。

select Keyword,count(*)
from TradeKeywords join News on charindex(TradeKeywords ,Title)>0
group by Keyword