修复一个行值,然后对 MySQL 中其他值的递减排序
我们先创建一个表 -
mysql> create table DemoTable ( id int ); Query OK, 0 rows affected (0.52 sec)
使用 insert 命令向表中插入一些记录 -
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values(7); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(8); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(6); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.12 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+------+ | id | +------+ | 10 | | 7 | | 8 | | 6 | | 9 | | 11 | +------+ 6 rows in set (0.00 sec)
以下是修复一个行值然后对其他值按降序排列的查询 -
mysql> select *from DemoTable order by id=10 DESC,id asc;
这将产生以下输出 -
+------+ | id | +------+ | 10 | | 6 | | 7 | | 8 | | 9 | | 11 | +------+ 6 rows in set (0.00 sec)
广告