Page 1 of 1

Work out average time

Posted: Tue Jun 21, 2005 8:22 am
by JayBird
Say i have a DB with 2 fields

start_time
end_time

both these contain UNIX timestamps.

i want to work out the average number of seconds between start_time and end_time.

Is it possible within one query, or will i need to do some calculation in php?

Ta

Posted: Tue Jun 21, 2005 9:34 am
by phpScott
since you are a guru I will point you in the right direction
http://dev.mysql.com/doc/mysql/en/group ... tions.html
the avg() mysql function will probably help

Posted: Tue Jun 21, 2005 9:52 am
by JayBird
wont that only be able to give me the average value of one column, not the average difference between two columns?

Posted: Tue Jun 21, 2005 9:55 am
by JayBird
seems to work

Code: Select all

SELECT AVG(time_finished - time_started) FROM responses

Posted: Tue Jun 21, 2005 10:27 am
by phpScott
thats what I was thinking. or you would have to sum each col first then do the avg thing