Reputation: 355
i show first and last log for each day from user 1 ,
alo i calculate the time differnece between first and last log.
so what i want is to calculate total sum of time difference something like
SUM(total)
here is what i run
SELECT id,device,userid,time, MIN(time) as Min, MAX(time) as Max, TIMEDIFF(MAX(time), MIN(time)) as total
FROM records WHERE userid='1' GROUP BY DATE(time)
so i want to get like
totalsum = =25:31:47
Upvotes: 1
Views: 126
Reputation: 28834
SUM
, you will need to reconvert it back to time by using SEC_TO_TIME() function.Try the following:
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC(derived_t.total) ) ) AS total_time_diff
FROM
(
SELECT TIMEDIFF(MAX(time), MIN(time)) as total
FROM records
WHERE userid='1'
GROUP BY DATE(time)
) AS derived_t
Upvotes: 1