Beegee | Essaye quelquechose comme ça :
Code :
- DROP TABLE requete3;
- CREATE TABLE requete3
- (bug NUMBER(9),
- date_modified DATE,
- old_value NUMBER(9),
- new_value NUMBER(9));
- INSERT INTO requete3 VALUES (140, TO_DATE('01/02/2005 14:36:54', 'DD/MM/YYYY HH24:MI:SS'), 10, 15);
- INSERT INTO requete3 VALUES (140, TO_DATE('02/02/2005 09:50:16', 'DD/MM/YYYY HH24:MI:SS'), 15, 20);
- INSERT INTO requete3 VALUES (140, TO_DATE('02/02/2005 12:07:36', 'DD/MM/YYYY HH24:MI:SS'), 20, 30);
- INSERT INTO requete3 VALUES (140, TO_DATE('02/02/2005 17:44:15', 'DD/MM/YYYY HH24:MI:SS'), 30, 20);
- INSERT INTO requete3 VALUES (140, TO_DATE('03/02/2005 13:43:23', 'DD/MM/YYYY HH24:MI:SS'), 20, 30);
- INSERT INTO requete3 VALUES (140, TO_DATE('22/02/2005 11:09:37', 'DD/MM/YYYY HH24:MI:SS'), 40, 45);
- INSERT INTO requete3 VALUES (140, TO_DATE('24/02/2005 18:33:05', 'DD/MM/YYYY HH24:MI:SS'), 45, 80);
- INSERT INTO requete3 VALUES (140, TO_DATE('04/03/2005 12:23:50', 'DD/MM/YYYY HH24:MI:SS'), 80, 90);
- INSERT INTO requete3 VALUES (140, TO_DATE('29/03/2005 15:05:40', 'DD/MM/YYYY HH24:MI:SS'), 90, 20);
- INSERT INTO requete3 VALUES (140, TO_DATE('29/03/2005 15:05:50', 'DD/MM/YYYY HH24:MI:SS'), 20, 15);
- INSERT INTO requete3 VALUES (140, TO_DATE('29/03/2005 15:11:25', 'DD/MM/YYYY HH24:MI:SS'), 15, 20);
- INSERT INTO requete3 VALUES (140, TO_DATE('09/06/2005 16:42:45', 'DD/MM/YYYY HH24:MI:SS'), 20, 30);
- INSERT INTO requete3 VALUES (140, TO_DATE('15/06/2005 11:39:25', 'DD/MM/YYYY HH24:MI:SS'), 30, 20);
- INSERT INTO requete3 VALUES (140, TO_DATE('29/06/2005 11:18:17', 'DD/MM/YYYY HH24:MI:SS'), 20, 30);
- INSERT INTO requete3 VALUES (140, TO_DATE('29/07/2005 10:12:38', 'DD/MM/YYYY HH24:MI:SS'), 30, 45);
- INSERT INTO requete3 VALUES (140, TO_DATE('18/08/2005 18:29:47', 'DD/MM/YYYY HH24:MI:SS'), 45, 80);
- INSERT INTO requete3 VALUES (140, TO_DATE('10/10/2005 12:17:49', 'DD/MM/YYYY HH24:MI:SS'), 80, 45);
- INSERT INTO requete3 VALUES (140, TO_DATE('20/10/2005 11:24:58', 'DD/MM/YYYY HH24:MI:SS'), 45, 40);
- INSERT INTO requete3 VALUES (140, TO_DATE('20/10/2005 11:25:20', 'DD/MM/YYYY HH24:MI:SS'), 40, 45);
- INSERT INTO requete3 VALUES (140, TO_DATE('17/01/2006 16:44:08', 'DD/MM/YYYY HH24:MI:SS'), 45, 80);
- INSERT INTO requete3 VALUES (140, TO_DATE('06/02/2006 10:15:46', 'DD/MM/YYYY HH24:MI:SS'), 80, 90);
- SELECT * FROM requete3;
- SELECT MIN(date_modified) FROM requete3
- WHERE date_modified >= TO_DATE('22/02/2005 11:09:37', 'DD/MM/YYYY HH24:MI:SS')
- AND date_modified <= TO_DATE('29/03/2005 15:05:40', 'DD/MM/YYYY HH24:MI:SS')
- AND EXISTS
- (SELECT 1
- FROM requete3
- WHERE date_modified =
- (SELECT MAX(date_modified)
- FROM requete3
- WHERE date_modified >= TO_DATE('22/02/2005 11:09:37', 'DD/MM/YYYY HH24:MI:SS')
- AND date_modified <= TO_DATE('29/03/2005 15:05:40', 'DD/MM/YYYY HH24:MI:SS'))
- AND new_value IN (80, 90))
- AND new_value IN (80, 90);
- => aucune ligne
- SELECT MIN(date_modified) FROM requete3
- WHERE date_modified >= TO_DATE('29/07/2005 10:12:38', 'DD/MM/YYYY HH24:MI:SS')
- AND date_modified <= TO_DATE('06/02/2006 10:15:46', 'DD/MM/YYYY HH24:MI:SS')
- AND EXISTS
- (SELECT 1
- FROM requete3
- WHERE date_modified =
- (SELECT MAX(date_modified)
- FROM requete3
- WHERE date_modified >= TO_DATE('29/07/2005 10:12:38', 'DD/MM/YYYY HH24:MI:SS')
- AND date_modified <= TO_DATE('06/02/2006 10:15:46', 'DD/MM/YYYY HH24:MI:SS'))
- AND new_value IN (80, 90))
- AND new_value IN (80, 90);
- => 18/08/2005 18:29:47
|
edit : exemple sous Oracle, à adapter pour un autre SGBD. |