如何按降序排列 MySQL 的输出结果?
如果我们想以降序排列结果集,需要在 ORDER BY 子句中指定 DESC(DESCENDING 的简写)关键字。
语法
Select column1, column2,…,columN From table_name ORDER BY column1[column2,…] DESC;
示例
在以下示例中,我们已按 'Id' 列以降序列出了结果集。
mysql> Select * from Student ORDER BY Id DESC; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 17 | Raman | Shimla | Computers | | 15 | Harshit | Delhi | Commerce | | 2 | Aarav | Mumbai | History | | 1 | Gaurav | Delhi | Computers | +------+---------+---------+-----------+ 4 rows in set (0.00 sec)
广告