如何使用单个查询对多列进行排序?\
mysqldatabasemysqli
首先我们创建一个表 −
mysql> create table DemoTable -> ( -> Id int, -> Value int -> ); Query OK, 0 rows affected (0.68 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(100,85885); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(101,885995474); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(100,895943); Query OK, 1 row affected (0.20 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
+------+-----------+ | Id | Value | +------+-----------+ | 100 | 85885 | | 101 | 885995474 | | 100 | 895943 | +------+-----------+ 3 rows in set (0.00 sec)
以下是对多列进行排序的查询 −
mysql> select Id,Value from DemoTable order by Value DESC;
输出
+------+-----------+ | Id | Value | +------+-----------+ | 101 | 885995474 | | 100 | 895943 | | 100 | 85885 | +------+-----------+ 3 rows in set (0.00 sec)