对 MySQL 中的一个列表排序,并在列表末尾显示固定结果?
让我们首先创建一个表,
mysql> create table DemoTable( FirstName varchar(100) ); Query OK, 0 rows affected (0.97 sec)
使用 insert 命令在表中插入一些记录,
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.27 sec)
使用 select 语句从表中显示所有记录,
mysql> select *from DemoTable;
这将产生以下输出,
+-----------+ | FirstName | +-----------+ | Chris | | Adam | | John | | Sam | | Mike | | David | +-----------+ 6 rows in set (0.00 sec)
以下是用于对列表进行排序并在末尾设置固定结果的查询,我们已将名称“Mike”设置在末尾,
mysql> select *from DemoTable order by FirstName='Mike',FirstName;
这将产生以下输出,
+-----------+ | FirstName | +-----------+ | Adam | | Chris | | David | | John | | Sam | | Mike | +-----------+ 6 rows in set (0.00 sec)
广告