MySQL - SUM from the group of time differences

I want to summarize the time difference to show the total number of hours a volunteer has worked. Getting the resulting set of time differences is easy:

Select timediff(timeOut, timeIn) 
FROM volHours 
WHERE username = 'skolcz'

which gives a list of times by the hour, but then I want to sum it up to the total.

So, if the result set is:

12:00:00
10:00:00
10:00:00
08:00:00

It is only 40 hours.

This is a way to do something like:

SELECT SUM(Select timediff(timeOut,timeIn) 
FROM volHours 
WHERE username = 'skolcz') as totalHours

?

+5
source share
3 answers
Select  SEC_TO_TIME(SUM(TIME_TO_SEC(timediff(timeOut, timeIn)))) AS totalhours
FROM volHours 
WHERE username = 'skolcz'

If not, then it is possible:

Select  SEC_TO_TIME(SELECT SUM(TIME_TO_SEC(timediff(timeOut, timeIn))) 
FROM volHours 
WHERE username = 'skolcz') as totalhours
+11
source

You will almost get an answer from Matthew , all you have to do is add a cast:

Select CAST(SUM(timediff(timeOut, timeIn)) as time) as totalhours
FROM volHours 
WHERE username = 'skolcz'    
+3
source

-

 Select SUM(timediff(timeOut, timeIn)) as total
 FROM volHours 
 WHERE username = 'skolcz'
+1

All Articles