如何在MySQL末尾对特定值排序?
为此,您可以使用ORDERBY。让我们创建一个表-
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)
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短