I'm looking for a solution to make a From Until chain from a set of records which have just one datetime.
The database table looks like this...
Code:
1 3232235778 test.php 2009-07-22 10:00:00
2 3232235778 page2.php 2009-07-22 11:00:00
3 3232235777 test.php 2009-07-22 10:30:00
4 3232235777 test.php 2009-07-22 11:15:00
5 3232235777 page2.php 2009-07-22 12:15:00
6 3232235778 page2.php 2009-07-22 12:00:00
What I'd like to do is a query like "Give me all IP in a given period with their start and end time"
If I want everyone that acces test.php between 07-22 09:00:00 and 07-22 11:00:00 it should return
Code:
3232235778 test.php 2009-07-22 10:00:00 2009-07-22 11:00:00
3232235777 test.php 2009-07-22 10:30:00 2009-07-22 12:15:00
So what the query needs to have is a way to make it kind of a chain from the datetime in the table.
From-Until / From-Until / From-Until etc. I also need to look around the border constraint to find the actual begin time.
It can be someone started accessing the page before the period I queried. The next page accessed is implicit the until time from the page visit
Code:
-- ----------------------------
-- Table structure for pagehits
-- ----------------------------
DROP TABLE IF EXISTS `pagehits`;
CREATE TABLE `pagehits` (
`PAGEHITS_ID` int(10) unsigned NOT NULL auto_increment,
`IP` int(10) unsigned default NULL,
`page` varchar(255) collate latin1_general_ci NOT NULL,
`datetime` datetime NOT NULL,
PRIMARY KEY (`PAGEHITS_ID`)
);
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `pagehits` VALUES ('1', '3232235778', 'test.php', '2009-07-22 10:00:00');
INSERT INTO `pagehits` VALUES ('2', '3232235778', 'page2.php', '2009-07-22 11:00:00');
INSERT INTO `pagehits` VALUES ('3', '3232235777', 'test.php', '2009-07-22 10:30:00');
INSERT INTO `pagehits` VALUES ('4', '3232235777', 'test.php', '2009-07-22 11:15:00');
INSERT INTO `pagehits` VALUES ('5', '3232235777', 'page2.php', '2009-07-22 12:15:00');
INSERT INTO `pagehits` VALUES ('6', '3232235778', 'page2.php', '2009-07-22 12:00:00');