0

我用字段表词:评级和出现。

TABLE: words
+----+----------+----------------+
| id |occurrence| rating         |
+----+----------+----------------+
| 1  | 0.2      |       2        |
| 2  | 0.1      |       1        |
| 3  | 0.5      |       3        |
+----+----------+----------------+

评级 它是按出现(asc)列排序的索引。所以首先我必须对所有记录进行排序,然后对评级列中的每个记录集索引进行排序。如何在 SQL 中做到这一点?

4

1 回答 1

4
UPDATE   words, (SELECT @rating := 0) init
SET      rating = (@rating := @rating + 1)
ORDER BY occurrence
于 2013-01-14T16:04:09.950 回答