Bonjour à tous,

Je voudrais faire une requête suivante :
Afficher les 50 premiers clients selon le tableau suivant :
[FONT=Arial] [/FONT][FONT=Arial]CA TOTAL[/FONT][FONT=Arial]MB TOTAL[/FONT][FONT=Arial]TX MB[/FONT][FONT=Arial]NB VOYAGES[/FONT][FONT=Arial]PANIER MOYEN[/FONT][FONT=Arial]CODE POSTAL[/FONT][FONT=Arial]CODE MAILING[/FONT][FONT=Arial]1 LIGNE PAR NOM CLIENT[/FONT][FONT=Arial] si typedossier <20 total=total+totalfacture[/FONT]
[FONT=Arial]si typedossier>20[/FONT]
[FONT=Arial]total=total-totalfacture[/FONT]
[FONT=Arial]((CA FACT - PAIEMENT FRNS) / NB PAX PRODUIT)[/FONT][FONT=Arial]MB / CA [/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial]TOTAL[/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial]TOTAL[/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT][FONT=Arial] [/FONT]
NB PAX = si typedossier<20 total=total +([FONT=Arial]adultes+enfants) sinon si typedossier>20 [FONT=Verdana]total=total -([/FONT][FONT=Arial]adultes+enfants )[/FONT][/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]voici la requete :[/FONT]
select top 50 facture.seqclt,client.nomclt,sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end)as ca,
sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end) -sum(facture.regle)as mb, case when sum(facture.total)<> 0
then (sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end)- sum(facture.regle)) / sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end) else sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end) - sum(facture.regle)end as taux, count(client.seqclt) as nbvoyage, case when sum(facture.adultes + facture.enfants) <> 0 then sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end)/(sum(case when facture.typedossier < 20 then facture.adultes + facture.enfants else 0 end)- sum(case when facture.typedossier > 20 then facture.adultes + facture.enfants else 0 end)) end as panmoyen , client.codemail, client.cp
from facture,vente,client where facture.seqvente = vente.seqvente and facture.seqclt = client.seqclt
group by facture.seqclt, client.nomclt, client.codemail, client.cp
order by ca desc
je teste par case when sum(facture.adultes + facture.enfants) <> 0 pour ne pas avoir une division par zéro.
je n'est pas réussi à trouver l'erreur "division par zéro", ce message est survenue lors de l'ajout de l'expression
sum(case when facture.typedossier < 20 then facture.total else 0 end)- sum(case when facture.typedossier > 20 then facture.total else 0 end)/(sum(case when facture.typedossier < 20 then facture.adultes + facture.enfants else 0 end)- sum(case when facture.typedossier > 20 then facture.adultes + facture.enfants else 0 end)) end as panmoyen
dans le requête.

Merci