Solved

Sum of Times

Posted on 2004-04-16
2
927 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:Edeldragon
2 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 10844255
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;
0
 
LVL 17

Accepted Solution

by:
leannonn earned 50 total points
ID: 10844318
You should convert time to seconds, sum it, and convert it back to time. This should do the trick:
---
SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(your_time_field))) ...
---
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikipedia.org/wiki/PHP  Very powerful.  But a…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now