mysql中實現按id排序的方法
1.首先,在命令行中啟動MySQL服務;
service mysql start
2.MySQL服務啟動后,在命令行中輸入mysql的用戶名和密碼登錄到MySQL;
mysql -u root -p
3.登錄到MySQL后,選擇使用一個數據庫,并在數據庫中查看表結構;
use mysql;
desc test_id;
+-----------+
| test_id |
+-----------+
| 8 |
| 7 |
| 6 |
| 5 |
| 4 |
| 3 |
| 2 |
| 10 |
| 1 |
+-----------+
4.查看到表結構后,使用server_id+0語句對ID的類型進行轉換;
select test_id from cardserver where game_id = 1 order by test_id+0 desc limit 10;
5.最后,ID的類型轉換后,重新查看表結構,即可看到ID排序成功;
desc test_id;
+-----------+
| test_id |
+-----------+
| 10 |
| 8 |
| 7 |
| 6 |
| 6 |
| 5 |
| 4 |
| 3 |
| 2 |
| 1 |
+-----------+