2013-06-13 50 views
3

我試圖按時間對一些結果進行排序。我收集str_to_date是要走的路,但我似乎使用它錯了,我不能確定,但​​我認爲它轉換爲NULL,然後不以有意義的方式排序:str_to_date在查詢中返回null,但它本身很好

mysql> SELECT member_id, result_result, str_to_date('result_result','%i:%s.%f') FROM results WHERE workout_id = '2' ORDER BY str_to_date('result_result','%i:%s.%f') LIMIT 5; 
+-----------+---------------+-----------------------------------------+ 
| member_id | result_result | str_to_date('result_result','%i:%s.%f') | 
+-----------+---------------+-----------------------------------------+ 
|   0 | 1:35.0  | NULL         | 
|   1 | 1:35.0  | NULL         | 
|   3 | 1:40   | NULL         | 
|   4 | 1:37.8  | NULL         | 
|   7 | 1:27.3  | NULL         | 
+-----------+---------------+-----------------------------------------+ 
5 rows in set, 5 warnings (0.00 sec) 

但兩個結果類型似乎轉換,如果我做手工精細:

mysql> select str_to_date('1:40','%i:%s.%f'); 
+--------------------------------+ 
| str_to_date('1:40','%i:%s.%f') | 
+--------------------------------+ 
| 00:01:40      | 
+--------------------------------+ 
1 row in set (0.00 sec) 

mysql> select str_to_date('1:35.0','%i:%s.%f'); 
+----------------------------------+ 
| str_to_date('1:35.0','%i:%s.%f') | 
+----------------------------------+ 
| 00:01:35       | 
+----------------------------------+ 
1 row in set (0.00 sec) 

任何想法發生了什麼/如何解決呢? 謝謝!

回答

2

你不需要函數內部的引號。試試

str_to_date(result_result, '%i:%s.%f') 
+0

冠軍!感謝那! – user2481801