2

Mysql表列是

Starttime - type:datetime, Stoptime - type:datetime

数据

Starttime, stoptime
2013-10-25 09:00:00, 2013-10-25 17:00:00
2013-10-26 09:00:00, 2013-10-26 17:00:00
2013-10-27 09:00:00, 2013-10-27 17:00:00
2013-10-28 09:00:00, 2013-10-28 17:45:00

询问

select, min(starttime), max(stoptime), 
SUM(TIME_TO_SEC(TIME_DIFF(stoptime - starttime))) total_hours from mytable

返回秒数,我可以使用...将其转换回时间TIME_TO_SEC()...它以格式为我提供结果,HH:MM:SS例如 28:45:00

但我需要将 28:45:00 转换为 28.75 小时格式。我怎么做?

4

2 回答 2

3
select, min(starttime), max(stoptime), 
SUM(TIME_TO_SEC(TIME_DIFF(stoptime - starttime))/3600) total_hours from mytable
于 2013-09-27T13:20:31.747 回答
0
SELECT 
MIN(starttime), 
MAX(stoptime), 
SUM(TIME_TO_SEC(TIMEDIFF(stoptime, starttime))/3600) AS total_hours 
FROM mytable
于 2014-05-26T10:44:15.230 回答