2010-08-30 64 views
0

我無法從條件選擇中輸出時間。目標是如果時間爲< 6h,則減去30分鐘。如何從IF條款返回時間

這裏是一個演示:

SELECT TIME(start_time) AS start, 
    TIME(end_time) AS end, 
    TIME_TO_SEC(TIMEDIFF(end_time, start_time)) AS durationSecs, 
    IF(
     TIMEDIFF(end_time, start_time) >= "06:00:00", 
     SUBTIME(TIMEDIFF(end_time, start_time), 30:0:0), 
     TIMEDIFF(end_time, start_time) 
    ) AS duration 
FROM [...] 

此代碼返回什麼,我認爲是時候了對象本身的字符串表示,例如30303a30353a3030。

我怎樣才能得到這個輸出的實際時間?

回答

2
SELECT TIME(start_time) AS start, 
    TIME(end_time) AS end, 
    TIME_TO_SEC(TIMEDIFF(end_time, start_time)) AS durationSecs, 
    IF(
     TIMEDIFF(end_time, start_time) >= "06:00:00", 
     TIMEDIFF(end_time - INTERVAL 30 MINUTE, start_time), 
     TIMEDIFF(end_time, start_time) 
    ) AS duration 
FROM [...] 
+0

工作,謝謝! – onik 2010-08-30 07:53:09