我有一个包含重复单词的表和一个名为“num”的空字段。
+----+--------------+-----+
| id | words | num |
+----+--------------+-----+
| 1 | red | |
+----+--------------+-----+
| 2 | blue | |
+----+--------------+-----+
| 3 | red | |
+----+--------------+-----+
| 4 | red | |
+----+--------------+-----+
| 5 | blue | |
+----+--------------+-----+
我想在 num 字段中插入重复单词的数量,如下所示:
+----+--------------+-----+
| id | words | num |
+----+--------------+-----+
| 1 | red | 1 |
+----+--------------+-----+
| 2 | blue | 1 |
+----+--------------+-----+
| 3 | red | 2 |
+----+--------------+-----+
| 4 | red | 3 |
+----+--------------+-----+
| 5 | blue | 2 |
+----+--------------+-----+
我怎样才能通过 php 或 sql 做到这一点?