Bonjour,
J'aimerai ajouter un critère sur une requête avec la fonction Year() mais celle-ci ne me retourne pas les bonnes valeur
Voici ma requête :
---------------------------------------------
SELECT a.ID_PANNE, a.LIBELLE, sum(a.nbr) as Somme
FROM (
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID1) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id1
WHERE p.ID_PANNE <> 1
GROUP BY p.ID_PANNE, p.LIBELLE
UNION
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID2) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id2
WHERE p.ID_PANNE <> 1
GROUP BY p.ID_PANNE, p.LIBELLE
UNION
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID3) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id3
WHERE p.ID_PANNE <> 1
GROUP BY p.ID_PANNE, p.LIBELLE ) as a
GROUP BY a.ID_PANNE,a.LIBELLE
---------------------------------------------
Je procède comme ceci :
---------------------------------------------
SELECT a.ID_PANNE, a.LIBELLE, sum(a.nbr) as Somme
FROM (
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID1) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id1
WHERE p.ID_PANNE <> 1 AND YEAR(E.DATE_RETOUR) = 2014
GROUP BY p.ID_PANNE, p.LIBELLE
UNION
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID2) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id2
WHERE p.ID_PANNE <> 1 AND YEAR(E.DATE_RETOUR) = 2014
GROUP BY p.ID_PANNE, p.LIBELLE
UNION
SELECT p.ID_PANNE, p.LIBELLE, count(E.PANNE_ID3) as nbr
FROM PANNE as P left outer join ENVOI as E ON
p.id_panne= e.panne_id3
WHERE p.ID_PANNE <> 1 AND YEAR(E.DATE_RETOUR) = 2014
GROUP BY p.ID_PANNE, p.LIBELLE ) as a
GROUP BY a.ID_PANNE,a.LIBELLE
---------------------------------------------
BDD :
ID_PANNE1 | ID_PANNE2 | ID_PANNE3 | DATE_RETOUR
2 | 5 | 5 | 2014
4 | 1 | 2 | 2014
Resultat :
ID_PANNE | LIBELLE | SOMME
2 | HS1 | 1 (Normalement 2)
4 | HS2 | 1
5 | HS3 | 1 (Normalement 2)
Si quelqu'un peu me guider vers la lumière ça serai cool