MySQL查询按时间戳和枚举排序?
为此,您可以使用ORDERBYDATE()
。让我们首先创建一个表。在这里,我们有一列的类型为DATE,另一列的类型为ENUM-
mysql> create table DemoTable -> ( -> JoiningDate date, -> Status ENUM('Good','Excellent','Bad') -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2019-01-21','Excellent'); mysql> insert into DemoTable(Status) values('Bad'); mysql> insert into DemoTable(Status) values('Good');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------+-----------+ | JoiningDate | Status | +-------------+-----------+ | 2019-01-21 | Excellent | | NULL | Bad | | NULL | Good | +-------------+-----------+ 3 rows in set (0.00 sec)
这是按时间戳和枚举排序的查询-
mysql> select *from DemoTable -> order by DATE(JoiningDate) ASC, Status asc;
这将产生以下输出-
+-------------+-----------+ | JoiningDate | Status | +-------------+-----------+ | NULL | Good | | NULL | Bad | | 2019-01-21 | Excellent | +-------------+-----------+ 3 rows in set (0.00 sec)