为此,您可以使用ORDER BY。让我们创建一个表-
mysql> create table demo57 −> ( −> id int not null auto_increment primary key, −> full_name varchar(20) −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo57(full_name) values('John Smith'); mysql> insert into demo57(full_name) values('David Miller'); mysql> insert into demo57(full_name) values('Not Known'); mysql> insert into demo57(full_name) values('Chris Brown');
使用select语句显示表中的记录-
mysql> select *from demo57;
这将产生以下输出-
+----+--------------+ | id | full_name | +----+--------------+ | 1 | John Smith | | 2 | David Miller | | 3 | Not Known | | 4 | Chris Brown | +----+--------------+ 4 rows in set (0.00 sec)
以下是在最后排序特定值的查询。
mysql> select *from demo57 −> order by(full_name="Not Known"),full_name desc;
这将产生以下输出-
+----+--------------+ | id | full_name | +----+--------------+ | 1 | John Smith | | 2 | David Miller | | 4 | Chris Brown | | 3 | Not Known | +----+--------------+ 4 rows in set (0.00 sec)