Add Field Time MySql

4

Dear, I have a table with a TIME-type column, which stores the time worked on the day, and I'm trying to add these times to the end of a month, but with no success.

I used the following query:

Query 1:

SELECT TIME_FORMAT((SELECT sum(TOTAL)  
FROM horario where PRESTADOR='NOME' 
and MONTH(data) = 1 and YEAR(data) = 2015), '%H:%i:%s') as total;

"null" result;

Query 2:

SELECT SEC_TO_TIME( SUM( TIME_TO_SEC(TOTAL))) AS total_horas
FROM horario where PRESTADOR='NOME' and MONTH(data) = 1 and YEAR(data) = 2015;

Result "6.14: 24: 00";

Query 3:

SELECT sum(TOTAL)  
FROM horario where PRESTADOR='NOME' 
and MONTH(data) = 1 and YEAR(data) = 2015;

Result: "1526400"; The correct result would be 158: 24: 00

    
asked by anonymous 03.03.2015 / 11:17

1 answer

3

Dear, thanks for the help, I was able to solve the problem using time_format, leaving the query like this:

SELECT time_format( SEC_TO_TIME( SUM( TIME_TO_SEC( TOTAL ) ) ),'%H:%i:%s') 
AS total_horas FROM horario where PRESTADOR='NOME' and MONTH(data) = 1 and YEAR(data) = 2015;
    
04.03.2015 / 12:43