让我们首先创建一个表-
mysql> create table DemoTable -> ( -> MonthNumber int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(1); mysql> insert into DemoTable values(9); mysql> insert into DemoTable values(6); mysql> insert into DemoTable values(8); mysql> insert into DemoTable values(5);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+-------------+ | MonthNumber | +-------------+ | 10 | | 1 | | 9 | | 6 | | 8 | | 5 | +-------------+ 6 rows in set (0.00 sec)
以下是按特定列排序的查询,并以升序显示其余记录-
mysql> select * from DemoTable -> order by MonthNumber=5 desc,MonthNumber asc;
这将产生以下输出-
+-------------+ | MonthNumber | +-------------+ | 5 | | 1 | | 6 | | 8 | | 9 | | 10 | +-------------+ 6 rows in set (0.00 sec)