日期:2014-05-16 浏览次数:20802 次
mysql> select * from test; +------+------+------+ | id | name | num1 | +------+------+------+ | 1 | a | 1 | | 2 | b | 2 | | 3 | c | 3 | | 5 | e | 5 | | 6 | f | 6 | +------+------+------+ 5 rows in set (0.00 sec) mysql> update test set num1=(select t.rownum from( -> select a.id,a.name,count(*) as rownum from test a,test b -> where a.num1>=b.num1 group by a.id,a.name) t where test.id=t.id); Query OK, 2 rows affected (0.02 sec) Rows matched: 5 Changed: 2 Warnings: 0 mysql> select * from test; +------+------+------+ | id | name | num1 | +------+------+------+ | 1 | a | 1 | | 2 | b | 2 | | 3 | c | 3 | | 5 | e | 4 | | 6 | f | 5 | +------+------+------+ 5 rows in set (0.00 sec) mysql>
------解决方案--------------------
如果你要重新对ID进行编号,只有导入到一张新的自增表中