57,062
社区成员
发帖
与我相关
我的任务
分享mysql> select * from tx;
+----+
| id |
+----+
| 0 |
| 1 |
| 2 |
| 4 |
| 6 |
| 8 |
| 9 |
+----+
7 rows in set (0.00 sec)
mysql> update tx t1,
-> (select id,(select count(*) from tx where id<t.id) as newid from tx t) t2
-> set t1.id=t2.newid
-> where t1.id=t2.id;
Query OK, 4 rows affected (0.06 sec)
Rows matched: 7 Changed: 4 Warnings: 0
mysql> select * from tx;
+----+
| id |
+----+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+----+
7 rows in set (0.00 sec)
mysql>