1 2 3 4 5 6 7 8 9 10 11 12
| select T.id_client,T.cli_rs,T.cli_exploit_ville,T.cli_fact_ville,T.cli_fact_same_adr,sum(V) as NbV,sum(C) as NbC,sum(VC) as NbTot
from (
select F.id_client,CL.cli_rs,CL.cli_exploit_ville,CL.cli_fact_ville,CL.cli_fact_same_adr,
case C.ct_nature_ct when 'V' then 1 when 'C' then 1 else 0 end as VC,
case C.ct_nature_ct when 'V' then 1 else 0 end as V,
case C.ct_nature_ct when 'C' then 1 else 0 end as C
from t_facture F inner join t_visite V on F.id_dossier = V.id_dossier
inner join t_client CL on F.id_client = CL.id_client
where V.valider = 1
and V.date between '20090101' and '20091231'
group by F.id_dossier) as T
group by T.id_client |
Partager