+------+------+ | id | name | +------+------+ | 1 | a | | 10 | b | | 11 | bb | | 2 | bb | | 5 | c | | 3 | f | | 6 | g | +------+------+
使用order by语句进行排序 mysql> select * from tn order by id desc; +------+------+ | id | name | +------+------+ | 6 | g | | 5 | c | | 3 | f | | 2 | bb | | 11 | bb | | 10 | b | | 1 | a | +------+------+ 7 rows in set (0.00 sec)
貌似是不起作用,因为id列的值存的是字符串类型的 解决: 使用字段+0解决
mysql> select * from tn order by id+0 desc; +------+------+ | id | name | +------+------+ | 11 | bb | | 10 | b | | 6 | g | | 5 | c | | 3 | f | | 2 | bb | | 1 | a | +------+------+ 7 rows in set (0.00 sec)
或者使用 字段*1解决 mysql> select * from tn order by id*1 desc; +------+------+ | id | name | +------+------+ | 11 | bb | | 10 | b | | 6 | g | | 5 | c | | 3 | f | | 2 | bb | | 1 | a | +------+------+ 7 rows in set (0.00 sec)