1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| With Consolidations
As
(
select personne_id,Year(date_couvert) annee,type_de_versement, priorite, sum(montant_versement) somme_versement
from Versements v
inner join type_de_versement tv
on v.type_de_versement=tv.type_de_versement
group by personne_id,Year(date_couvert),type_de_versement, priorite
)
Select
from
( select personne_id, min(annee) min_annee
from Consolidations
group by personne_id
) T
inner join
(
select personne_id, annee,min(priorite) min_priorite
From Consolidations C
group by personne_id, annee
) P
on T.personne_id=P.personne_id
and T.min_annee=P.Annee
inner join Consolidation
on c.Personne_id=P.personne_id
and c.annee=P.Annee
and c.priorite=P.min_priorite |
Partager