要重新排序除值0以外的整数,请使用以下语法-select *from yourTableName order by yourColumnName=0 ,yourColumnName;
让我们首先创建一个表-mysql> create table reorderIntegerExcept0
-> (
-> value int
-> );
以下是使用insert命令在表中插入记录的查询-mysql> insert into reorderIntegerExcept0 values(90);
mysql> insert into reorderIntegerExcept0 values(10);
mysql> insert into reorderIntegerExcept0 values(0);
mysql> insert into reorderIntegerExcept0 values(40);
mysql> insert into reorderIntegerExcept0 values(0);
mysql> insert into reorderIntegerExcept0 values(50);
mysql> insert into reorderIntegerExcept0 values(80);
mysql> insert into reorderIntegerExcept0 values(0);
mysql> insert into reorderIntegerExcept0 values(300);
以下是使用select语句显示表中所有记录的查询-mysql> select * from reorderIntegerExcept0;
这将产生以下输出-+-------+
| value |
+-------+
| 90 |
| 10 |
| 0 |
| 40 |
| 0 |
| 50 |
| 80 |
| 0 |
| 300 |
+-------+
9 rows in set (0.00 sec)
以下是对整数进行重新排序的查询,值0除外-mysql> select * from reorderIntegerExcept0 order by value =0 ,value;
这将产生以下输出-+-------+
| value |
+-------+
| 10 |
| 40 |
| 50 |
| 80 |
| 90 |
| 300 |
| 0 |
| 0 |
| 0 |
+-------+
9 rows in set (0.00 sec)
如果您希望以降序排列除0以外的整数,请使用以下查询-mysql> select * from reorderIntegerExcept0 order by value =0,value DESC;
这将产生以下输出-+-------+
| value |
+-------+
| 300 |
| 90 |
| 80 |
| 50 |
| 40 |
| 10 |
| 0 |
| 0 |
| 0 |
+-------+
9 rows in set (0.00 sec)