I'm trying to get the average of Completed time, so at first, I'm getting the completed time of individual processOrders.
下面的查询将获取单个 processOrders 的完成时间。
select processorder_prod_number,ifnull(time(round( timediff(max(completed_time),
min(start_time)))) ,'00:00:00') as `completedtime`
from processorder_prod where week(start_time)=week(curdate())
group by processorder_prod_number;
输出是这样的
+--------------------+----------------+
| processorder_number| completedtime |
+--------------------+----------------+
| 1002135897 | 01:42:15 |
| 1002135898 | 01:39:43 |
| 1002135900 | 05:31:52 |
| 1002135901 | 02:31:52 |
+--------------------+----------------+
当我尝试获取总时间,即 sum(completedtime) 时,它得到了错误的输出。
select count(distinct processorder_prod_number),time(round(sum(completedtime))) as totaltime from
(select processorder_prod_number,ifnull(time(round( timediff(max(completed_time),
min(start_time)))) ,'00:00:00') as `completedtime`
from processorder_prod where week(start_time)=week(curdate())
group by processorder_prod_number) as t;
上述查询的输出
+---------------------------+----------------+
| count(processorder_number)| completedtime |
+---------------------------+----------------+
| 4 | 01:42:15 |
+---------------------------+----------------+
请在我做错的地方帮助我。欢迎任何建议和更正,在此先感谢。
最佳答案
在这里,您将获得已完成时间的总和。
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time` ) ) ) AS `completedtime` FROM dual;
更新的答案
SELECT COUNT(DISTINCT processorder_prod_number), TIME(ROUND(SUM(completedtime))) AS totaltime FROM (SELECT processorder_prod_number, IFNULL(SEC_TO_TIME( SUM( TIME_TO_SEC( `completed_time` ) ) ),'00:00:00') AS `completedtime` FROM processorder_prod WHERE WEEK(start_time)=WEEK(CURDATE()) GROUP BY processorder_prod_number) AS t;
关于mysql - Mysql中时间戳的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48562122/