Sum of the hours between two dates

5

I would like to know how I could get the hours between date_ini and end_date

EQUIPO    TIPO_MANTE    FECHA_INI    FECHA_FIN   Horas   TOTAL
LAPTOP        A         12/20/18     12/21/18    24       50
DESKTOP       A         12/20/18     12/21/18    24       400
LAPTOP        A         12/20/18     12/23/18    72       100
LAPTOP        B         12/21/18     12/22/18    24       200
LAPTOP        A         12/22/18     12/24/18    24       50

that in this case it would be my query to get the hours

SELECT S.Equipo, S.Tipo_mante, HOUR( TIMEDIFF( T.Fecha_fin, T.Fecha_ini ) ) 
AS  'difirencia' 
FROM orden_trabajo t
LEFT JOIN solicitud_mante s ON S.Id_soli = T.Id_soli
WHERE S.Tipo_mante =  'Inmediato'
GROUP BY S.Equipo, S.Tipo_mante
HAVING COUNT( * ) >1

But it would be that if the same TEAM AND THE SAME MAINTENANCE are repeated that I add the hours I have tried to do the sum but it gives me error

    
asked by Pantunez 24.12.2018 в 18:07
source

1 answer

3

You should only add the date range to your query,

Your PHP variables would be $ FI for start date, and $ FF for end date

SELECT S.Equipo, S.Tipo_mante, SUM( t.Total ) AS TOTAL
FROM solicitud_mante s
LEFT JOIN orden_trabajo t ON s.Id_soli = t.Id_soli
WHERE (S.Tipo_mante =  "Inmediato") AND (S.Fecha_fin BETWEEN '$FI' AND '$FF')
GROUP BY S.Equipo, S.Tipo_mante
HAVING COUNT( * ) >1
    
answered by 24.12.2018 / 19:03
source