Bonjour,
J'ai une base avec des tables de plus de 7000 lignes et pour 3 d'entre elles ( PROJET, PLANNING, COMMENTAIRE) je veux afficher le dernier commentaire de tous PLANNING confondus de chaque projet
Plus de 300 projets avec chacun au moins 10 planning donc afficher le planning ayant la date de commentaire la plus recente ainsi que le codeProjet et le nom du PROJET associé.
Un exemple avec les 3 tables (cijoint un fichier avec l'exemple car n'arrive pas à inserer les table ):
PROJET
id codeProjet NomProjet commentaireProjet
-------------------------------------------------------------------
11 001 Projet1
12 002 Projet2 Amenagement
PLANNING
id nomPlanning projet_id
-------------------------------------------------------------------
71 Planning1 12
72 Planning2 12
73 Planning3 12
74 Planning4 12
COMMENTAIRE
id date_derniere_modif id_objet type_objet Commentaire
---------------------------------------------------------------------
91 2010-04-12 72 PLANNING MAJ1_Planning_2
92 2010-05-25 72 PLANNING MAJ2_Planning_2
93 2010-09-11 73 PLANNING MAJ1_Planning_3
94 2010-10-12 11 PROJET Creation Projet1
95 2011-03-19 74 PLANNING MAJ1_Planning_4
96 2011-06-21 72 PLANNING MAJ3_Planning_2
97 2011-07-14 12 PROJET MAJ Projet2
98 2011-09-27 73 PLANNING MAJ2_Planning_3
Ma requête :
le resultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 SELECT PROJ.codeProjet, PROJ.nomProjet, PLAN.nomPlanning, COMMENT.date_derniere_modif as date_modif ,COMMENT.commentaire FROM PROJET PROJ LEFT JOIN PLANNING PLAN ON PROJ.id = PLAN.project_id LEFT JOIN COMMENTAIRE COMMENT ON COMMENT. date_derniere_modif = (select max(C.date_derniere_modif) from COMMENTAIRE C where C.id_ojet = PLAN.id ) WHERE PROJ.commentaireProjet IS NOT NULL GROUP BY PROJ.codeProjet, PROJ.nomProjet, PLAN.nomPlanning, COMMENT.date_derniere_modif, COMMENT.commentaire
codeProjet nomProjet nomPlanning date_modif commentaire
-----------------------------------------------------------------------
002 Projet2 Planning2 2011-06-21 MAJ3_Planning2
002 Projet2 Planning3 2011-09-27 MAJ2_Planning3
002 Projet2 Planning4 2011-03-19 MAJ1_Planning4
Mais voici ce que je veux extraire et aficher
codeProjet nomProjet nomPlanning date_modif commentaire
----------------------------------------------------------------------
002 Projet2 Planning3 2011-09-27 MAJ2_Planning_3
Quelqu'un a-t-il une idée de la solution et merci de votre reponse à
l 'avance ?
Partager