您可以field()
为此使用。让我们首先创建一个表-
mysql> create table DemoTable ( Value int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(70); mysql> insert into DemoTable values(60); mysql> insert into DemoTable values(56); mysql> insert into DemoTable values(81); mysql> insert into DemoTable values(85);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-------+ | Value | +-------+ | 10 | | 70 | | 60 | | 56 | | 81 | | 85 | +-------+ 6 rows in set (0.00 sec)
以下是对ORDER BY特定3个值的查询,分别为降序和其余升序-
mysql> select *from DemoTable order by field(Value,60,70,81) desc;
输出结果
+-------+ | Value | +-------+ | 81 | | 70 | | 60 | | 10 | | 56 | | 85 | +-------+ 6 rows in set (0.00 sec)