我有一个包含数千个关键字的表。我想分离出该表中排名前25位的负面关键字,然后从这些关键字创建一个连接来查找与另一个表中的关键字关联的句子。最终结果将为id_file
,sentence_id
,sentiment
,sentence
,token
。两个表都有令牌。SQL Server从另一个表中的一个表中选择最高记录
令牌表(tbl_token
)具有以下的列:
id_file, sentence_id, sentiment, token
的过滤器,以隔离从tbl_token
顶部25如下:
id_file = 3, sentiment = 'negative'
语句表(tbl_sentence
)具有以下各栏:
id_file, sentence_id, sentiment, **sentence**, token
两个表中的sentence_id都有一对多的关系,所以加入这些关系就会把句子拉出来。来自顶部查询的令牌存在于tbl_sentence
中。
我现在的解决方案是首先运行tbl_token
的前25位,对于上面的相同过滤器,计数令牌,按降序排序。
SELECT TOP (25)
COUNT(token) AS Count, token
FROM
tbl_token
GROUP BY
token, sentiment, id_file
HAVING
(sentiment = N'negative') AND (id_file = 3)
ORDER BY
COUNT(token) DESC
然后我把它链接到一个视图中的所有令牌,其中有sentence_id
。然后,我可以将sentence_id
从视图链接到tbl_sentence
,以根据前25个否定关键字分隔句子。
这个工程,但我只是想知道这是否可以在一个存储过程中完成。
只是告诉你want..thanks –