with master_r08 as (select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(tch_traffic_erlang) as traffic_erl
                         , sum(payload_mbyte)      as payload_mbyte
                    from r08.meas_2g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(volte_traffic_erl) as traffic
                         , sum(payload_mbyte)     as payload_mbyte
                    from r08.meas_4g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , 0            as traffic
                         , sum(payload) as payload_mbyte
                    from r08.meas_5g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id),
     master_r09 as (select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(tch_traffic_erlang) as traffic_erl
                         , sum(payload_mbyte)      as payload_mbyte
                    from r09.meas_2g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(volte_traffic_erl) as traffic
                         , sum(payload_mbyte)     as payload_mbyte
                    from r09.meas_4g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , 0            as traffic
                         , sum(payload) as payload_mbyte
                    from r09.meas_5g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id),
     master_r11 as (select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(tch_traffic_erlang) as traffic_erl
                         , sum(payload_mbyte)      as payload_mbyte
                    from r11.meas_2g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , sum(volte_traffic_erl) as traffic
                         , sum(payload_mbyte)     as payload_mbyte
                    from r11.meas_4g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id

                    union all

                    select n.region
                         , n.tech
                         , m.date
                         , site_id
                         , 0            as traffic
                         , sum(payload) as payload_mbyte
                    from r11.meas_5g_daily m
                             join network_cell n on m.network_cell_id = n.id
                    where m.date between '2023-12-01' and '2023-12-07'
--                      and n.site_id in ('AMB002')
                    group by n.region
                           , n.tech
                           , m.date
                           , site_id),
     combined as (select *
                  from master_r08
                  union all
                  select *
                  from master_r09
                  union all
                  select *
                  from master_r11)
select region
     , tech
     , date
     , site_id
     , traffic_erl::numeric(100, 2)   as traffic_erl
     , payload_mbyte::numeric(100, 2) as payload_mbyte
from combined
order by region, tech, site_id, date
;