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 28 29 30 31 32 33 34 35 36 37
|
select activites_prev.mois , activites_prev.nb ,activites_real.nb
from /*Sélectionner tous les mois à partir des dates prevues et réelles avec le code du plan */
(select plan,to_char(dateprev,'yyyy-mm') mois
from activites
where plan =:V_PLAN
and (dateprev between :datedeb and :datefin)
union
select plan ,to_char(datereal,'yyyy-mm') mois
from activites
where plan =:V_PLAN
and (datereal between :datedeb and :datefin) )activites_princ,
( select code ,to_char(dateprev,'yyyy-mm') mois , count(*) nb
FROM activites
where plan =:V_PLAN
and (dateprev between :datedeb and :datefin)
group by plan ,to_char(dateprev,'yyyy-mm')
union /*le cas ou la dateprev n'appartient pas a durée de date*/
select plan, to_char(datereal,'yyyy-mm') mois , 0 nb
FROM activites
where plan =:V_PLAN
and (dateprev < :datedeb or dateprev> :datefin)
and (datereal between :datedeb and :datefin) ) activites_prev,
( select plan ,to_char(datereal,'yyyy-mm') mois , count(*) nb
FROM activites
where plan =:V_PLAN
and (datereal between :datedeb and :datefin) and datereal is not null
group by plan ,to_char(datereal,'yyyy-mm')
union /* le cas ou la datereal est null ou la date prev appartient à durée de date*/
select plan ,to_char(dateprev,'yyyy-mm') mois , 0 nb
FROM activites
where plan =:V_PLAN and datereal is null
and dateprev between :datedeb and :datefin ) activites_real
where activites_princ.plan =activites_prev.plan
and activites_real.plan =activites_prev.plan
and activites_real.mois=activites_prev.mois
and activites_princ.mois =activites_prev.mois |
Partager