Mysql 计算两次的持续时间

Mysql 计算两次的持续时间,mysql,sql,Mysql,Sql,嗨,我是sql的新手,我正在尝试计算两次的对数 例: timestart=21:00 时间结束=03:00 结果将是06:00 对于compute,我的查询是这样的,但它给出了18:00的结果。我将非常感谢任何帮助或添加。谢谢 TIME_FORMAT(ABS(SEC_TO_TIME(ABS(TIME_TO_SEC(timestart)-TIME_TO_SEC(timeend)))), '%H:%i') 使用案例: time_format(sec_to_time(case when times

嗨,我是sql的新手,我正在尝试计算两次的对数

例: timestart=21:00 时间结束=03:00 结果将是06:00

对于compute,我的查询是这样的,但它给出了18:00的结果。我将非常感谢任何帮助或添加。谢谢

 TIME_FORMAT(ABS(SEC_TO_TIME(ABS(TIME_TO_SEC(timestart)-TIME_TO_SEC(timeend)))), '%H:%i')
使用
案例

time_format(sec_to_time(case when timestart < timeend
                             then time_to_sec(timeend) - time_to_sec(timestart) 
                             else 24*60*60 + time_to_sec(timeend) - time_to_sec(timestart)
                        end), '%H:%i'
           )
time\u格式(秒到时间(timestart
使用
案例

time_format(sec_to_time(case when timestart < timeend
                             then time_to_sec(timeend) - time_to_sec(timestart) 
                             else 24*60*60 + time_to_sec(timeend) - time_to_sec(timestart)
                        end), '%H:%i'
           )
time\u格式(秒到时间(timestart
大家好,欢迎使用SO和MySQL。您好,欢迎访问SO和MySQL。看见