1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
SELECT
COALESCE(a_ouv.NB_ACTION,0) AS NB_ACTION_OUV,
COALESCE(a_all.NB_ACTION,0) AS NB_ACTION,
COALESCE(r_ouv.NB_RISQUE_OUV,0) AS NB_RISQUE_OUV,
COALESCE(r_all.NB_RISQUE,0) AS NB_RISQUE,
COALESCE(r_acc.NB_ACCEPTABLE,0) AS NB_ACCEPTABLE
FROM
projet p
LEFT JOIN (SELECT COUNT(*) AS NB_RISQUE, r.identifiant_projet FROM risque r WHERE 1=1 '.$filtre.' GROUP BY r.identifiant_projet) AS r_all
ON r_all.identifiant_projet=p.identifiant_projet
LEFT JOIN (SELECT COUNT(*) AS NB_RISQUE_OUV, r.identifiant_projet FROM risque r WHERE r.statut_risque="Ouvert" '.$filtre.' GROUP BY r.identifiant_projet) AS r_ouv
ON r_ouv.identifiant_projet=p.identifiant_projet
LEFT JOIN (SELECT SUM(IF(GREATEST(COALESCE(r.gravite_planning,0), COALESCE(r.gravite_cout,0), COALESCE(r.gravite_performance,0), COALESCE(r.gravite_accident,0)) * r.probabilite <= p.acceptabilite, 1, 0)) AS NB_ACCEPTABLE, r.identifiant_projet FROM risque r JOIN projet p ON r.identifiant_projet=p.identifiant_projet WHERE 1=1 '.$filtre.' GROUP BY r.identifiant_projet) AS r_acc
ON r_acc.identifiant_projet=p.identifiant_projet
LEFT JOIN ( SELECT COUNT(*) AS NB_ACTION, a.identifiant_projet FROM action a LEFT JOIN risque r ON r.identifiant_risque = a.identifiant_risque WHERE 1=1 '.$filtre.' GROUP BY a.identifiant_projet) AS a_all
ON a_all.identifiant_projet=p.identifiant_projet
LEFT JOIN ( SELECT COUNT(*) AS NB_ACTION, a.identifiant_projet FROM action a LEFT JOIN risque r ON r.identifiant_risque = a.identifiant_risque WHERE a.statut_action="Ouvert" '.$filtre.' GROUP BY a.identifiant_projet) AS a_ouv
ON a_ouv.identifiant_projet=p.identifiant_projet
WHERE
p.identifiant_projet=:identifiant_projet |
Partager