在MySQL中计算总持续时间 [英] Calculating total time duration in MySQL

查看:117
本文介绍了在MySQL中计算总持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的表格数据

i have a table data like this

(int)   (time)  [mySQL datatype]

Id     Duration 
------------------
1      00:10:00
2      10:10:00
3      03:00:00
4      04:13:00

我想从该表计算总持续时间,我们该怎么做.就像17:33:00. 有人可以提供mysql查询来计算吗?

i want to calculate the total duration from this table, how can we do it. like 17:33:00. Could anybody please provide mysql query to calculate this.

推荐答案

尝试转换为秒,求和,然后转换回时间:

Try converting to seconds, summing, then converting back to a time:

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(Duration)))
FROM Table1

结果:

17:33:00

这篇关于在MySQL中计算总持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆