1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
CREATE TABLE IF NOT EXISTS `T_inter` (
`ID_intervention` smallint(6) NOT NULL auto_increment,
`ID_user` smallint(6) NOT NULL ,
`CODE_intervention` smallint(6) NOT NULL ,
`DATE_intervention` date NOT NULL ,
PRIMARY KEY (`ID_intervention`)
) ;
INSERT INTO `T_inter` (`ID_intervention`, `ID_user`, `CODE_intervention`, `DATE_intervention`) VALUES
(1,1, 255, '2012-08-05'),
(2,3, 1603, '2012-08-05'),
(3,1, 8, '2012-08-06'),
(4,3, 1, '2012-08-07'),
(5,3, -1, '2012-08-08'),
(6,2, 0, '2012-08-08'),
(7,1, 1, '2012-08-08'),
(8,1, -1, '2012-08-09'),
(9,1, 0, '2012-08-10');
SELECT p1.ID_intervention, p1.ID_user, p1.CODE_intervention, p1.DATE_intervention
FROM t_inter p1 INNER JOIN ( SELECT ID_user, MAX(DATE_intervention) MAXDATE_intervention FROM t_inter GROUP BY ID_user ) P2
ON p1.DATE_intervention = MAXDATE_intervention and p1.ID_user =p2.ID_user; |
Partager