Work out average time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Work out average time

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

wont that only be able to give me the average value of one column, not the average difference between two columns?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

seems to work

Code: Select all

SELECT AVG(time_finished - time_started) FROM responses
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

thats what I was thinking. or you would have to sum each col first then do the avg thing
Post Reply