如何使用mysql计算时间 [英] How to sum time using mysql
本文介绍了如何使用mysql计算时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在表格中总结时间.在我的表中有持续时间字段,类型是时间".
I have to sum the time in a table. In my table there is duration field and the type is "time" .
我试过这个查询,它只返回几秒钟.但我需要小时、分钟和秒.
I have tried this query it returns only seconds. but I need hours and minutes and seconds.
在我的表中有两行,一行是 00:20:10,另一行是 00:15:05
in my table there is two rows one row has 00:20:10 and another is 00:15:05
所以我需要显示为 00:35:15
so I need to display as 00:35:15
SELECT SEC_TO_TIME( SUM( MINUTE( duration ) ) ) AS totaltime
FROM users
推荐答案
请试试这个:
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `duration` ) ) ) AS totaltime
这篇关于如何使用mysql计算时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文