Mysql
 sql >> Database >  >> RDS >> Mysql

mysql aggiorna una colonna con un int in base all'ordine

SET @rownumber = 0;    
update mytable set Moneyorder = (@rownumber:[email protected]+1)
order by MoneyOrder asc

oppure puoi provare a farlo in un'unica query

update mytable target
join
(
     select id, (@rownumber := @rownumber + 1) as rownum
     from mytable         
     cross join (select @rownumber := 0) r
     order by MoneyOrder asc
) source on target.id = source.id    
set Moneyorder = rownum