我有一个名为'order_details_child'的表,其描述如下所示
mysql> desc order_details_child;
+------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------+------+-----+---------+-------+
| vendor_id | varchar(50) | YES | | NULL | |
| item_id | varchar(20) | YES | | NULL | |
| date_of_order | varchar(10) | YES | | NULL | |
| time_of_order | varchar(10) | YES | | NULL | |
+------------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
我有一个要求,我需要根据升序顺序中的 time_of_order 来检索记录?
order by time_of_order asc ?? (First ordered should be shown first)
这是样本记录
+----------------------+-----------+---------+---------------+---------------+--------+
| order_child_id | vendor_id | item_id | date_of_order | time_of_order | status |
+----------------------+-----------+---------+---------------+---------------+--------+
| 1410070300301030O1O1 | 1 | 5 | 2014-10-07 | 15:10:30 | NEW |
+----------------------+-----------+---------+---------------+---------------+--------+
1 row in set (0.00 sec)
请有人帮帮我。
答案 0 :(得分:1)
ORDER BY STR_TO_DATE(time_of_order,'%T')ASC
%T = 24小时hh:mm:ss - 您的意思是时间还是指日期?
请参阅http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format