Avg mysql time difference

Is there a function to find the average time difference in the standard time format in my sql.

+4
source share
2 answers

You can use timestampdiff to find the difference between two points.

I'm not sure what you mean by "average." Average at the table? Average value per line?

If it is a table or a subset of rows:

 select avg(timestampdiff(SECOND, startTimestamp, endTimestamp)) as avgdiff from table 

The avg function works like any other aggregate function and responds to group by . For instance:

 select col1, avg(timestampdiff(SECOND, startTimestamp, endTimestamp)) as avgdiff from table group by col1 

This will give you average differences for each individual col1 value.

Hope this makes you point in the right direction!

+13
source

I like to do

 SELECT count(*), AVG(TIME_TO_SEC(TIMEDIFF(end,start))) FROM table 

It also gives the number of lines ...

+4
source

All Articles