Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
with agregat_metier as (
select
a.d1,a.c1,a.c2,b.c3,b.c4,b.c5,c.c6,c.c7,sum(c.c8) c8
from
t1 a
join t2 b on a.t2_id = b.id
join t3 c on b.t3_id = c.id
where
a.d1 between to_date(&dte_min,'YYYY-MM-DD') and to_date(&dte_max,'YYYY-MM-DD')
group by
a.d1,a.c1,a.c2,b.c3,b.c4,b.c5,c.c6,c.c7
)
select
a.d1,d.ca,d.cb,d.cc,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6,a.c7,a.c8
from
t4 d
join agregat_metier a on d.t1_id = a.id
where
d.cd in ('R1','R2','AB3')
and d.ce = &filtre1
union
select
a.d1,d.ca,d.cb,d.cc,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6,a.c7,a.c8
from
t4 d
join agregat_metier a on d.t1_id = a.id
where
d.cd in ('R2','ZZ4','ZZ8')
and d.ce = &filtre2
union
select
a.d1,d.ca,d.cb,d.cc,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6,a.c7,a.c8
from
t4 d
join agregat_metier a on d.t1_id = a.id
where
d.cd in ('R1','ZZ8','AB3')
and d.ce = &filtre3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.