views:

295

answers:

1

Hi i have this query:

SELECT avg( duration ) as average FROM `login`;

The datatype for duration is "time", thus my value is like: 00:00:14, 00:20:23 etc

I execute the query it gives me: 2725.78947368421

What is that? I want in time format, can mysql do the average on time??

+2  A: 

Try this:

SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(`login`))) FROM Table1;

Test data:

CREATE TABLE `login` (duration TIME NOT NULL);
INSERT INTO `login` (duration) VALUES
('00:00:20'),
('00:01:10'),
('00:20:15'),
('00:06:50');

Result:

00:07:09
Mark Byers
additionally you can divide the results of time_to_sec by 60 to get a number result.
John M