2010-08-30 69 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