-1

我正在尝试对连续出现的所有单词进行分组,计算它们的频率值并按计数结果排序。它只能在 sql 中完成。这是一个例子:

我有下表:

word | freq
-----------
car  | 5
cake | 2
car  | 4

并希望得到这个结果:

word | freq
-----------
car  | 9
cake | 2
4

2 回答 2

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
于 2012-08-12T18:38:35.223 回答
1
SELECT word, SUM(freq) AS freq FROM yourTable GROUP BY word ORDER BY freq DESC;
于 2012-08-12T18:38:46.513 回答