如何获得mysql的时间总和?
问题描述:
如何计算存储在MySQL列中的时间总和? 表名:时间表如何获得mysql的时间总和?
+----------+
| hours |
+----------+
| 02:00:00 |
| 03:30:00 |
| 04:30:00 |
| 05:30:00 |
| 06:00:00 |
| 07:00:00 |
| 08:00:00 |
| 09:00:00 |
+----------+
我需要输出:45:30:00
。 我试着用下面的SQL
select sum(hours) from timesheet ;
却是露出449000
能否请您通过适当的SQL指正?
答
您可以使用SEC_TO_TIME和TIME_TO_SEC date time functions
select SEC_TO_TIME(sum(TIME_TO_SEC(hours))) from timesheet ;
请检查这个问题,这可能是帮助你[Sackoverflow问题(http://*.com/questions/3054123/calculate-a-sum-of -type-time-using-sql) – Apoorva
'select SEC_TO_TIME(sum(TIME_TO_SEC(hours)))from timeheet;' – Damith
Yah !!它正在工作。非常感谢你@Damith。 – Mihir