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
| SELECT pdv.id_pdv AS ID,
m.num_mois,
m.nom_mois,
CONCAT(e.nom_enseigne, ' ',pdv.nom) AS Magasin_d,
COALESCE(COUNT(rp.id_reporting_prod), 0) AS Nb_Prod,
SUM(case rp.stock when '0' then 1 else 0 end) AS Rupture
FROM pdv
CROSS JOIN mois m
LEFT JOIN planning p
ON p.id_pdv=pdv.id_pdv
LEFT JOIN reporting_produit rp
ON rp.id_planning=p.id_planning
AND m.num_mois=EXTRACT(MONTH FROM p.date_rdv)
AND YEAR(p.date_rdv)='".$annee."'
JOIN pdv_enseigne e
ON pdv.enseigne=e.id_enseigne
AND pdv.enseigne='".$_GET['id']."'
GROUP BY pdv.id_pdv, m.num_mois
ORDER BY pdv.nom, m.num_mois |
Partager