i want to know please how i can put union of table 2014 to 2017 only in loop in this query:
select xxx, xxx, xxx,
from (
select
colonne,
colonne,
from CA
left join (
select
xx,
sum(xx) as xx,
xx
from (
select
sum(MONTANT) as MONTANT,
CONCAT(NUM_SIN, CLE_SIN) as cle,
EXER_SIN
from fa
where CD_TYP_CNT='PREV'
group by NUM_SIN, CLE_SIN, EXER_SIN
union
select
sum(MONTANT) as MONTANT,
CONCAT(NUM_SIN, CLE_SIN) as cle,
EXER_SIN
from table2014
where CD_TYP_CNT='PREV'
group by NUM_SIN, CLE_SIN, EXER_SIN
union
select
sum(MONTANT) as MONTANT,
CONCAT(NUM_SIN, CLE_SIN) as cle,
EXER_SIN
from table2015
where CD_TYP_CNT='PREV'
group by NUM_SIN, CLE_SIN, EXER_SIN
union
select
sum(MONTANT) as MONTANT,
CONCAT(NUM_SIN, CLE_SIN) as cle,
EXER_SIN
from table2016
where CD_TYP_CNT='PREV'
group by NUM_SIN, CLE_SIN, EXER_SIN
union
select
sum(MONTANT) as MONTANT,
CONCAT(NUM_SIN, CLE_SIN) as cle,
EXER_SIN
from table2017
where CD_TYP_CNT='PREV'
group by NUM_SIN, CLE_SIN, EXER_SIN ) as tab
group by cle, EXER_SIN) as reglmt on reglmt.cle = CPM.dossiers
left join (
select
CONCAT(colonne, colonne) as cle,
from production
group by colonne, colonne1, colonne3, colonne4) as xx on ptf_CPM.cle = CPM.dossiers
group by xx, xx
) as xx where vérif <> 0