Link to home
Start Free TrialLog in
Avatar of Edeldragon
Edeldragon

asked on

Sum of Times

Hi Experts

I've got a query that returns a whole lot of times in H:MM:SS format. I want to sum all of these to find the total of the column. If I try:

select sum(Times) from (select timediff(time2, time1) as Times from my_table) then the value I get is
a) an integer when I was hoping for either a time or a real number of hours and
b) doesn't agree with the total if I try the same thing in Excel (the values differ by 53 hours (I think it's hours) in the examples I've tried, so it doesn't even look like rounding errors.

Thanks

ED
Avatar of snoyes_jw
snoyes_jw
Flag of United States of America image

Unless you have some other reason, I don't see why you need a subquery.  It may just be an issue of the format; give the following a shot:

SELECT TIME_FORMAT(SUM(TIMEDIFF(time2, time1)), '%H:%i:%s') FROM my_table;
ASKER CERTIFIED SOLUTION
Avatar of Aleksandar Bradarić
Aleksandar Bradarić
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial