2015-03-13 62 views
0

我試圖根據date_of_ordertime_of_order獲得近5個訂單通過下表中領域,這兩個領域的數據類型是varchar並且這裏的order_child_id是一些不按順序存儲的隨機數。如何獲得最近根據日期和時間5場這是爲varchar

如何爲此編寫查詢?

order_details_child表:

+------------------+------------+---------------+---------------+ 
| order_child_id | vendor_id | date_of_order | time_of_order | 
+------------------+------------+---------------+---------------+ 
| 2000010313044428 | 5060091713 | 2015-03-11 | 16:44:28  | 
| 2000010313044920 | 5060091713 | 2015-03-13 | 16:49:20  | 
| 2000010313044951 | 5060091713 | 2015-03-11 | 16:49:51  | 
| 2002880313043941 | 5000818755 | 2015-03-13 | 16:39:41  | 
| 2002880313044029 | 5000818755 | 2015-03-12 | 16:40:29  | 
| 3000010313044555 | 5060091713 | 2015-03-12 | 16:45:55  | 
| 4000010313044555 | 5000818755 | 2015-03-13 | 16:45:55  | 
+------------------+------------+---------------+---------------+ 

回答

3

這是你在找什麼?

select od.* 
from order_details od 
order by date_of_order desc, time_of_order desc 
limit 5; 

您應該以本機格式存儲日期和時間。但如果出於某種原因無法使用,則格式是將它們存儲爲字符串的正確方法。