如何在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 生日广州男生祝福语简短