mysql压缩order_by值

时间:2012-10-09 19:12:42

标签: mysql

我有一个表格,其列号为order_by whit,值为Ex:

4,10 ,20 ,80,500,625,712

我想修改为:

1,2,3,4,5,6,7

如果80的顺序为4,则该值为4

我想做这样的事情:

UPDATE tablex SET order_by=ORDER_OF(order_by);

1 个答案:

答案 0 :(得分:3)

set @rownum := 0;
UPDATE tablex as t
SET t.order_by = @rownum := @rownum + 1
order by t.order_by

SQLFiddle example