我有一個包含數千個關鍵字的表。我想分離出該表中排名前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 –