开发者

How to return time from IF-clause

I'm having trouble outputting a time from a conditional select. The aim is to subtract 30min if the time is < 6h.

Here is a demo:

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, star开发者_Go百科t_time)
    ) AS duration
FROM [...]

This code returns what I think is a string representation of the TIME object itself, for example 30303a30353a3030 .

How can I get this to output the actual times?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜