以下是按多列排序的语法-
select *from yourTableName order by yourColumnName1 DESC,yourColumnName2,yourColumnName3;
让我们创建一个表-
mysql> create table demo29 −> ( −> value1 int, −> value2 int −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo29 values(10,500); mysql> insert into demo29 values(14,400); mysql> insert into demo29 values(9,500); mysql> insert into demo29 values(13,400); mysql> insert into demo29 values(45,500); mysql> insert into demo29 values(11,400);
使用select语句显示表中的记录-
mysql> select *from demo29;
这将产生以下输出-
+--------+--------+ | value1 | value2 | +--------+--------+ | 10 | 500 | | 14 | 400 | | 9 | 500 | | 13 | 400 | | 45 | 500 | | 11 | 400 | +--------+--------+ 6 rows in set (0.00 sec)
以下是按多列排序的查询-
mysql> select *from demo29 −> order by value2 desc,value1;
这将产生以下输出-
+--------+--------+ | value1 | value2 | +--------+--------+ | 9 | 500 | | 10 | 500 | | 45 | 500 | | 11 | 400 | | 13 | 400 | | 14 | 400 | +--------+--------+ 6 rows in set (0.00 sec)