MySQL 中的多列排序?
让我们首先创建一个表格 -
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)
广告