How to calculate sum of times store in a column in mysql ? table name : timesheet
如何计算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 |
+----------+
I need output : 45:30:00
. I tried with the below sql
我需要输出:45:30:00。我尝试使用下面的sql
select sum(hours) from timesheet ;
But it is showing 449000
can you please correct me with proper sql ?
但它显示449000你能用正确的SQL纠正我吗?
1 个解决方案
#1
2
You can use SEC_TO_TIME and TIME_TO_SEC date time functions
您可以使用SEC_TO_TIME和TIME_TO_SEC日期时间功能
select SEC_TO_TIME(sum(TIME_TO_SEC(hours))) from timesheet ;
#1
2
You can use SEC_TO_TIME and TIME_TO_SEC date time functions
您可以使用SEC_TO_TIME和TIME_TO_SEC日期时间功能
select SEC_TO_TIME(sum(TIME_TO_SEC(hours))) from timesheet ;