1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| with a as (
----------------pour recupere le num_produit et le montant jointure entre 3 table -------------------
select hrc.num_produit,mvt.montant
from d_mouvement mvt
left join d_contrat on ctr.num_surcpte=mvt.num_compte
left join role_contrat on hrc.cod_produit=ctr.cod_produit and hrc.num_contrat=ctr.num_contrat
)
select
num_produit,
case when montant >10000 then (select count(*) from a group by num_produit ) else null end as "Superieur_a_10000",
case when montant >=10000 and montant <=15000 then (select count(*) from a group by num_produit ) else null end as "Superieur_a_10",
case when montant >15000 and montant <=20000 then (select count(*) from a group by num_produit) else null end as "Entre_15_20",
case when montant >20000 and montant <=30000 then (select count(*) from a group by num_produit) else null end as "Entre_20_30",
case when montant >30000 then (select count(*) from a group by num_produit ) else null end as "Superieur_a_30"
from a ; |