Brug:
SELECT t.user_id,
SEC_TO_TIME(SUM(TIME_TO_SEC(t.endtime) - TIME_TO_SEC(t.starttime))) AS timediff
FROM MYTABLE t
GROUP BY t.user_id
Trin:
- Brug TIME_TO_SEC at konvertere TID til sekunder for matematisk operation
- Summer forskellen
- Brug SEC_TO_TIME for at konvertere sekunderne tilbage til TIME
Baseret på eksempeldataene ville jeg lige have foreslået:
SELECT t.user_id,
TIMEDIFF(MIN(t.startdate), MAX(t.enddate)) AS timediff
FROM MYTABLE t
GROUP BY t.user_id