我用字段表示单词:评级和发生。
TABLE: words
+----+----------+----------------+
| id |occurrence| rating |
+----+----------+----------------+
| 1 | 0.2 | 2 |
| 2 | 0.1 | 1 |
| 3 | 0.5 | 3 |
+----+----------+----------------+
评级它是按发生(asc)列排序的索引。 首先,我必须对所有记录进行排序,然后对于评级列中的每个记录集索引。如何在SQL中执行此操作?
答案 0 :(得分:4)
UPDATE words, (SELECT @rating := 0) init
SET rating = (@rating := @rating + 1)
ORDER BY occurrence