I'm doing the following query:
SELECT SEC_TO_TIME(sum(Total_Segundos_Consumidos)/count(distinct IDTRANSACTIONS)) AS 'Tempo Médio'
FROM
(SELECT IDTRANSACTIONS,
SUM(TIME_TO_SEC(TimeDiff(TIME_FORMAT(DATEFIM,'%H:%i'),
TIME_FORMAT(DATEINI,'%H:%i')))) AS Total_Segundos_Consumidos
FROM TEMPO
GROUP BY IDTRANSACTIONS) AS Q
And it's not working.
The following error appears:
Bad format for Time '-05: 46: 27.2727' in column 1
This is because, when you run only the command inside, it has negative numbers:
-80340, -86040
Examples in link
My goal is to take care of the time and take an average of the time. In the link above, I put the times of one of the users to serve as an example.