为此,请使用ORDER BY FIELD()ASC。让我们首先创建一个表-create table DemoTable(Title varchar(100));
使用插入命令在表中插入一些记录-insert into DemoTable values('Java');
insert into DemoTable values('C');
insert into DemoTable values('Python');
insert into DemoTable values('MongoDB');
使用select语句显示表中的所有记录-select *from DemoTable;
这将产生以下输出-+---------+
| Title |
+---------+
| Java |
| C |
| Python |
| MongoDB |
+---------+
4 rows in set (0.00 sec)
以下是按任意关键字排序的查询-select *from DemoTable order by FIELD(Title,'MongoDB,C,Python,Java') ASC;
这将产生以下输出-+---------+
| Title |
+---------+
| Java |
| C |
| Python |
| MongoDB |
+---------+
4 rows in set (0.00 sec)