lasnoufle La seule et unique! | Quel SGBD?
A voir ton "group by mois" a la fin de ta requete, je pense que tu voulais plus faire quelque chose comme ca: Select mois, MAX(CA2013), MAX(CA2014) From
(Select 'Janvier' as mois, CAST(Sum(TTC_Montant - TVA_Montant) As Decimal(4,4)) AS CA2013, 0.0 AS CA2014
From
Documents
Where FastFilter <> 0 And Removed <> 1 and
(2013) = EXTRACT(YEAR FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact)) and (01)=EXTRACT(Month FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact)) union Select 'Janvier' as mois, 0.0 AS CA2013, CAST(Sum(TTC_Montant - TVA_Montant) As Decimal(4,4)) AS CA2014
From
Documents
Where FastFilter <> 0 And Removed <> 1 and
(2014) = EXTRACT(YEAR FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact)) and (01)=EXTRACT(Month FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact))
)
Group by mois |
La facon dont ta requete initiale est ecrite fait que le "group by" s'applique seulement a la deuxieme requete de l'union plutot qu'a l'ensemble (enfin je pense) ce qui explique pourquoi tu obtiens toujours deux lignes pour Janvier.
Sinon autre option, passer les requetes en sous-requetes dans une clause SELECT (le "FROM dual" c'est du Oracle, a adapter si pas Oracle): Select 'Janvier' as mois,
(Select CAST(Sum(TTC_Montant - TVA_Montant) As Decimal(4,4)) From Documents Where
FastFilter <> 0 And Removed <> 1 and (2013) = EXTRACT(YEAR FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact)) and
(01)=EXTRACT(Month FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact))) AS CA2013,
(Select CAST(Sum(TTC_Montant - TVA_Montant) As Decimal(4,4)) From Documents Where
FastFilter <> 0 And Removed <> 1 and (2014) = EXTRACT(YEAR FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact)) and
(01)=EXTRACT(Month FROM IF(NoFact = '' THEN (IF(NoLivr = '' THEN DateCmde Else DateLivr)) ELSE DateFact))) AS CA2014
FROM dual |
---------------
C'était vraiment très intéressant.
|