Hi,
Im lookiing for a query to get previous row
my table structure is like this
CREATE TABLE `test` (
`id` INT(5) NOT NULL AUTO_INCREMENT,
`service` INT(5) NOT NULL,
`timestamp` DATETIME NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = MyISAM;
INSERT INTO `test` (`id`, `service`, `timestamp`) VALUES
(1, 1, '2010-02-21 13:52:37'),
(2, 2, '2010-02-23 16:52:37'),
(3, 3, '2010-02-27 20:52:37'),
(4, 4, '2010-02-18 21:52:37'),
(5, 3, '2010-03-01 01:52:37'),
(6, 2, '2010-03-02 13:52:37'),
(7, 1, '2010-03-03 04:52:47'),
(8, 4, '2010-03-04 18:52:47'),
(9, 3, '2010-03-21 13:52:47'),
(10, 1, '2010-03-08 02:53:01'),
(11, 2, '2010-03-08 04:53:01'),
(12, 4, '2010-03-08 15:53:01'),
(13, 3, '2010-03-08 12:53:03'),
(14, 2, '2010-03-08 14:53:03'),
(15, 1, '2010-03-08 03:53:04'),
(16, 4, '2010-03-08 20:53:13'),
(17, 1, '2010-03-08 23:53:14'),
(18, 2, '2010-03-08 13:53:15');
SELECT * FROM test t where `timestamp` BETWEEN '2010-03-08 00:00:00' AND '2010-03-08 23:59:59' order by `service`,`timestamp`
Results is
id service timestamp
10 1 2010-03-08 02:53:01
15 1 2010-03-08 03:53:04
17 1 2010-03-08 23:53:14
11 2 2010-03-08 04:53:01
18 2 2010-03-08 13:53:15
14 2 2010-03-08 14:53:03
13 3 2010-03-08 12:53:03
12 4 2010-03-08 15:53:01
16 4 2010-03-08 20:53:13
I want to list all service with time stamp between mentioned date time and also previous row less than ā2010-03-08 00:00:00ā for each service
my result should be like as given below
id service timestamp
[B][COLOR="Red"]7 1 2010-03-03 04:52:47[/COLOR][/B]
10 1 2010-03-08 02:53:01
15 1 2010-03-08 03:53:04
17 1 2010-03-08 23:53:14
[B][COLOR="Red"]6 2 2010-03-02 13:52:37[/COLOR][/B]
11 2 2010-03-08 04:53:01
18 2 2010-03-08 13:53:15
14 2 2010-03-08 14:53:03
[B][COLOR="Red"]5 3 2010-03-01 01:52:37[/COLOR][/B]
13 3 2010-03-08 12:53:03
[B][COLOR="Red"]8 4 2010-03-04 18:52:47[/COLOR][/B]
12 4 2010-03-08 15:53:01
16 4 2010-03-08 20:53:13
can anyone help me with writing a query to get result as above.
thanks in advance