单独计算天数就足够了。
这是我使用的串联。
我用一个完全复制/可粘贴的示例进行说明,以方便理解我们达到的限制(TIME 格式的最大值)
捆绑了一个免费的独角兽以简化逗号管理
SELECT 'pq7~' AS unicorn
#######################
## Expected result ##
#######################
## Total, formatted as days:hh:mm:ss ##
,CONCAT(
FLOOR(TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24') / 86400)
, ':'
, SEC_TO_TIME(TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24') % 86400)
) AS Real_expected_result
#########################
## Calculation details ##
#########################
## Extracted days from diff ##
,FLOOR(TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24') / 86400) AS Real_days
## Extracted Hours/minutes/seconds from diff ##
,SEC_TO_TIME(TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24') % 86400) AS Real_hours_minutes_seconds
###################################
## Demo of wrong values returned ##
###################################
,TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24') AS Real_seconds_diff
## WRONG value returned. 5.64M is truncated to 3.02 ! ##
,TIME_TO_SEC(SEC_TO_TIME(5644119)) AS WRONG_result
## Result is effectively limited to 838h59m59s ##
,SEC_TO_TIME(TIMESTAMPDIFF(SECOND, '2017-01-01 09:17:45', '2017-03-07 17:06:24')) AS Limit_hit
## Lights on said limit ##
,SEC_TO_TIME( 3020398) AS Limit_value_check1
,SEC_TO_TIME( 3020400) AS Limit_value_check2