我正在尝试对连续出现的所有单词进行分组,计算它们的频率值并按计数结果排序。它只能在 sql 中完成。这是一个例子:
我有下表:
word | freq
-----------
car | 5
cake | 2
car | 4
并希望得到这个结果:
word | freq
-----------
car | 9
cake | 2
我正在尝试对连续出现的所有单词进行分组,计算它们的频率值并按计数结果排序。它只能在 sql 中完成。这是一个例子:
我有下表:
word | freq
-----------
car | 5
cake | 2
car | 4
并希望得到这个结果:
word | freq
-----------
car | 9
cake | 2
您可以按单词分组,然后根据组进行汇总......
SELECT word,SUM(freq) AS freq FROM tblName GROUP BY word
当您必须根据频率对单词进行排序时,您可以通过以下方式使用 ORDER BY:
SELECT word,SUM(freq) AS freq FROM tblName GROUP BY word ORDER BY freq DESC
SELECT word, SUM(freq) AS freq FROM yourTable GROUP BY word ORDER BY freq DESC;