mysql> create table test (id int unsigned AUTO_INCREMENT PRIMARY KEY, sort tinyint not null) engine=innodb;
Query OK, 0 rows affected (0.79 sec)
mysql> insert into test (sort) values (0),(0),(0),(0);
Query OK, 4 rows affected (0.18 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from test;
+----+------+
| id | sort |
+----+------+
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 0 |
+----+------+
4 rows in set (0.00 sec)
mysql> set @a:=0;
Query OK, 0 rows affected (0.00 sec)
mysql> update test set sort = @a:=@a+1 order by id desc;
Query OK, 4 rows affected (0.20 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> select * from test;
+----+------+
| id | sort |
+----+------+
| 1 | 4 |
| 2 | 3 |
| 3 | 2 |
| 4 | 1 |
+----+------+
4 rows in set (0.00 sec)
mysql>