Bonjour,
Voila la requete ci-dessous me donne, après verif, des resultats cohérents.
Malheureusement elle dure 30 secondes ou +. Et ca c pas bon.
Bref j'aimerais savoir comment l'optimiser.
select A.agent_id,S.MAXI,T.MAXI,U.MAXI,V.MAXI,W.MAXI,X.MAXI
FROM agent A,
(SELECT agent_id,SUM(commande_prix) MAXI
FROM agent
LEFT JOIN commande ON (agent_id=commande_ori_agent_id)
WHERE ( agent_id!="" )
GROUP BY 1 ) S,
(SELECT agent_id,SUM(affaire_ca_realise) MAXI
FROM agent
LEFT JOIN affaire ON (agent_id=affaire_agent_affect)
WHERE ( agent_id!="" )
GROUP BY 1 ) T,
(SELECT agent_id,SUM(action_rdv_ca) MAXI
FROM agent
LEFT JOIN action_rdv ON (agent_id=action_rdv_agent_affect)
WHERE ( agent_id!="" )
GROUP BY 1 ) U,
(SELECT agent_id,COUNT(DISTINCT commande_id) MAXI
FROM agent
LEFT JOIN commande ON (agent_id=commande_ori_agent_id)
WHERE ( agent_id!="" )
GROUP BY 1 ) V,
(SELECT agent_id,COUNT(DISTINCT affaire_id) MAXI
FROM agent
LEFT JOIN affaire ON (agent_id=affaire_agent_affect)
WHERE ( agent_id!="" )
GROUP BY 1 ) W,
(SELECT agent_id,COUNT(DISTINCT action_rdv_id) MAXI
FROM agent
LEFT JOIN action_rdv ON (agent_id=action_rdv_agent_affect)
WHERE ( agent_id!="" )
GROUP BY 1 ) X
WHERE A.agent_id=U.agent_id AND A.agent_id=T.agent_id
AND A.agent_id=V.agent_id AND A.agent_id=W.agent_id
AND A.agent_id=X.agent_id AND A.agent_id=S.agent_id
order by 1
Partager