Mysql Average on time column?

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??

This question and answers originated from www.stackoverflow.com
Question by (2/7/2010 2:59:35 PM)

Answer

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
Answer by

Find More Answers
Related Topics  mysql  query  time  average
Related Questions
  • Average Time to Reply to Message

    Is it possible to calculate the average time to reply to a message just with the following columns: id | ref | client | admin | date | message id is the unique message number ref is the m…
  • MySQL sort by average of two averages

    I am working on a contest site where there are two types of users, normal site members, and judges. Each can use a drag and drop tool to order the entries in a particular contest in the order they c…
  • SQL Work out the average time difference between total rows

    I've searched around SO and can't seem to find a question with an answer that works fine for me. I have a table with almost 2 million rows in, and each row has a MySQL Date formatted field. I'd l…
  • What's the most efficient way to get the horizontal average in a MySQL query?

    I have the following MySQL-table Id | One | Two | Three ---------------------------- 1 | 10 | 30 | 20 2 | 50 | 60 | 20 3 | 60 | NULL | 40 Edit: Of course the table doesn't need to be …
  • Java Time Specific Average

    I have a text file: DATE 20090105 1 2.25 1.5 3 3.6 0.099 4 3.6 0.150 6 3.6 0.099 8 3.65 0.0499 DATE 20090105 DATE 20090106 1 2.4 1.40 2 3.0 0.5 5 3.3 0.19 7 2.75 0.5 10 2.75 0.25 DATE 20090106 DA…
  • MySQL Average of column where there are greater than 5 rows

    Is there any way to use MySQL to only return an average if there are more than X rows? I am currently using the following query: SELECT round(AVG(a_points),1) as a from points where user_id=X …
  • Moving average - MySQL

    I'm trying to implement system-wide login throttling and I need to calculate the daily average number of failed login attempts from the last 3 months. I'm currently inserting a record on every lo…
  • phpmyadmin average time

    I am working with a joomla helpdesk component (Huruhelpdesk) and i need to work a query to see the average time of the tickets since the user open the ticket (start_date) till the reps close the tic…
  • MySQL Union and Average

    I've no idea if I am using UNION correctly in this scenario - there may well be a better/easier way and I'm open to suggestions: I have the following code: SELECT COUNT(*), AVG (q1) AS q1, AVG…
  • MySQL Daily Average over a month

    I'm pulling several status over a specific time period and I'd like to pull another stat that would be "average sales per day" over this time period. I'm not sure how to do daily averages over a spe…