0

I want to calculate the average difference between multiple dates: sent_date & view_date.

My table structure look like:

CREATE TABLE `mails` (
  `m_id` int(8) NOT NULL AUTO_INCREMENT,
  `sent_date` date NOT NULL DEFAULT '0000-00-00',
  `view_date` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`l_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

Example data:

sent_date: 2013-06-01 view_date: 2013-06-02 difference: 2 days

sent_date: 2013-06-01 view_date: 2013-06-05 difference: 4 days

Average: 3 days

4

1 回答 1

6

Use DATEDIFF() and AVG()

select avg(datediff(view_date, sent_date))
from mails
于 2013-06-14T13:38:03.203 回答