I have a call log for my Widget sales staff. Each click in a customer record is logged. Staff may access the same customer account several times a day, so there could be dozens of consecutive clicks grouped together under the same recordID at different times of the day.
Example:
recordID userID date_event
33450 321 2013-06-20 16:22:02
33450 321 2013-06-20 16:22:02
33450 321 2013-06-20 16:22:24
33450 321 2013-06-20 16:22:24
22222 321 2013-06-20 16:22:53
22222 321 2013-06-20 16:22:54
12345 321 2013-06-20 16:23:43
12345 321 2013-06-20 16:23:44
12345 321 2013-06-20 16:24:00
12345 321 2013-06-20 16:24:05
12345 321 2013-06-20 16:24:05
12345 321 2013-06-20 18:16:09
12345 321 2013-06-20 18:16:09
33450 321 2013-06-20 18:33:24
33450 321 2013-06-20 18:35:11
33450 321 2013-06-20 18:36:55
12345 321 2013-06-20 19:01:14
98765 321 2013-06-20 19:02:43
In the data set above, I would have 6 groups of access.
first last duration(seconds)
33450 2013-06-20 16:22:02 2013-06-20 16:22:24 22
22222 2013-06-20 16:22:30 2013-06-20 16:22:54 24
12345 2013-06-20 16:23:43 2013-06-20 18:16:09 6746
33450 2013-06-20 18:33:24 2013-06-20 18:36:55 211
12345 2013-06-20 19:01:14 2013-06-20 19:01:14 0
98765 2013-06-20 19:02:43 2013-06-20 19:02:43 0
The duration is meant to be an estimate and not actual time where eyes are on a record. I can't detect when Staff actively using this app, or when they are using a client side tool, looking up data in another application or website.
The table structure is:
CREATE TABLE IF NOT EXISTS `record_log` (
`event_id` int(11) NOT NULL AUTO_INCREMENT,
`userID` int(5) DEFAULT NULL,
`recordID` int(10) DEFAULT NULL,
`date_event` datetime DEFAULT NULL,
PRIMARY KEY (`event_id`),
KEY `userID` (`userID`),
KEY `date_event` (`date_event`),
KEY `recordID` (`recordID`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
What would be the best way to structure a query to return the second dataset? Can this be done in one query without using too many cycles? I would potentially have thousands of accessed records on a given day.