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

hakre
  • 193,403
  • 52
  • 435
  • 836
Citizen SP
  • 1,411
  • 7
  • 36
  • 68

1 Answers1

6

Use DATEDIFF() and AVG()

select avg(datediff(view_date, sent_date))
from mails
juergen d
  • 201,996
  • 37
  • 293
  • 362