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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| with nb_heures_et_montants as
(select t1.id nomi_id, t6.id ent_id, t1.nbheure as Nb_heures, round(t1.montant,2) as montant
from table1 t1
inner join EntbleAnnee t2 on t1.idrefEntnnee = t2.id
inner join EntbleRelation t3 on t1.referenceContrat = t3.id
inner join tableEtablissement t4 on t3.idrefsal = t4.id
inner join tableRecap t5 on t5.id=t1.idrefTableRecap
inner join tableEtablissement t6 on t6.id=t5.idreft6
inner join tablePersonne t7 on ..................
......
.....
where t2.annee >= 2017
and t6.numentreprise='123456'
),
nb_heures_et_montants_pivot as
(select nomi_id, ent_id,
a2017_nb_heures, a2018_nb_heures, a2019_nb_heures, a2020_nb_heures,
a2017_montant, a2018_montant, a2019_montant, a2020_montant
from
pivot (sum(nb_heures) nb_heures, sum(montant) montant for annee in (2017 as a2017, 2018 as a2018, 2019 as a2019, 2020 as a2020))
)
select distinct
sal.numerocontrat as "NUM.contrat",
tpers.nom as NOM,
tpers.prenom as PRENOM,
hm.a2017_nb_heures as "nbheure_2017",
hm.a2017_montant as "montant_2017",
hm.a2018_nb_heures as "nbheure_2018",
hm.a2018_montant as "montant_2018",
hm.a2019_nb_heures as "nbheure_2019",
hm.a2019_montant as "montant_2019",
hm.a2020_nb_heures as "nbheure_2020",
hm.a2020_montant as "montant_2020"
FROM table1 nomi
inner join EntbleAnnee c1 on nomi.idrefEntnnee = c1.id
inner join EntbleRelation trel on nomi.referenceContrat = trel.id
inner join tableEtablissement sal on sal.id = trel.idrefsal
inner join tableEtablissement Ent on Ent.id = trel.idgrp_1
inner join tablePersonne tpers on tpers.x530_idx510 = sal.idx510
inner join tableRecap trec on trec.d020_idd010 = c1.id
inner join nb_heures_et_montants_pivot hm on hm.nomi_id = Ent.id and hm.ent_id = Ent.id
where ................
and ......................
and ..................
and c1.annee = 2020
and Ent.numentreprise in ('123456')
; |
Partager