0

Basically i'm attempting to get an average based on two time stamps inside a database, let's say for example i have a product, I insert it into the database 10 times with an listed_time and a sell_time, I want to group all 10 rows together and find the average between both the listed_time and the sell_time to find on average on how long it took to sell.

EDIT : timestamps are inserted as time() not date()

The code in which i tried and failed to work was

$query = $db->runSQL("SELECT AVG(TIMESTAMPDIFF(SECOND, listed_time, sell_time)) from trade");
while($row = mysql_fetch_assoc($query)) {
    echo $row['AVG(TIMESTAMPDIFF(SECOND, listed_time, sell_time))']."</br>";
}
Curtis Crewe
  • 4,126
  • 5
  • 26
  • 31
  • Possible duplicate: [How to find the average time difference between rows in a table](http://stackoverflow.com/questions/876842/how-to-find-the-average-time-difference-between-rows-in-a-table) – nickhar Apr 18 '13 at 14:13

1 Answers1

2

You can try this for that 10 rows:

SELECT AVG(TIMESTAMPDIFF(SECOND, listed_time, sell_time ) ) as za_avg ...

This will give you the average time (for those 10 rows) it took to sell the items

Stephan
  • 8,000
  • 3
  • 36
  • 42