with master as (select n.tech
                     , m.date
                     , n.site_id

                     , sum(tch_traffic_erlang) as traffic
                     , 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
                      ('NTK015', 'NTK073', 'COK059', 'BTI904', 'NTK068', 'TMR063', 'NTK081', 'NTK077', 'NTK047', 'COK036', 'NTK071', 'NTK002', 'NTK075', 'BTI905', 'COK188', 'NTK080', 'NAB205', 'TIM425', 'TUL219', 'NTK056', 'NTK079', 'NAB204', 'NTK082', 'NTK074', 'COK117', 'NTK067', 'TMB035',
                       'TMB171', 'TIM427', 'MSH629', 'TIM461', 'WRS112', 'MWR700', 'NLA383', 'MWR699', 'JAP830', 'SON523', 'BTI906', 'MSH630', 'BIA282', 'NAB211', 'BIA281', 'JAP823', 'AMB025', 'JAP827', 'NAB208', 'JAP826', 'NLA009', 'COK500', 'COK502', 'TIM462', 'NAB207', 'JAP828', 'NAB210',
                       'COK501', 'BTI907', 'MWR707', 'NAB209', 'WAM015', 'NAB029', 'MRK820', 'MRK821', 'KEP066', 'FFK159', 'BIA009', 'TIM183', 'AGA044', 'SON524', 'WRS113', 'WRS114', 'KMN060', 'JAP829', 'TMR064', 'COK503', 'SRU129', 'FFK360', 'AGA045', 'COK171', 'JAP925', 'MSH002', 'SON515',
                       'MWR705', 'MWR706', 'JAP831', 'MRK822', 'TIM463', 'AMB039', 'SRU130', 'JAP832', 'COK180', 'COK191', 'NLA006', 'COK211', 'COK340', 'MSH626', 'SON433', 'COK190')
                group by n.tech
                       , m.date
                       , n.site_id

                union

                select n.tech
                     , m.date
                     , n.site_id

                     , 0                    as traffic
                     , sum(m.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
                      ('NTK015', 'NTK073', 'COK059', 'BTI904', 'NTK068', 'TMR063', 'NTK081', 'NTK077', 'NTK047', 'COK036', 'NTK071', 'NTK002', 'NTK075', 'BTI905', 'COK188', 'NTK080', 'NAB205', 'TIM425', 'TUL219', 'NTK056', 'NTK079', 'NAB204', 'NTK082', 'NTK074', 'COK117', 'NTK067', 'TMB035',
                       'TMB171', 'TIM427', 'MSH629', 'TIM461', 'WRS112', 'MWR700', 'NLA383', 'MWR699', 'JAP830', 'SON523', 'BTI906', 'MSH630', 'BIA282', 'NAB211', 'BIA281', 'JAP823', 'AMB025', 'JAP827', 'NAB208', 'JAP826', 'NLA009', 'COK500', 'COK502', 'TIM462', 'NAB207', 'JAP828', 'NAB210',
                       'COK501', 'BTI907', 'MWR707', 'NAB209', 'WAM015', 'NAB029', 'MRK820', 'MRK821', 'KEP066', 'FFK159', 'BIA009', 'TIM183', 'AGA044', 'SON524', 'WRS113', 'WRS114', 'KMN060', 'JAP829', 'TMR064', 'COK503', 'SRU129', 'FFK360', 'AGA045', 'COK171', 'JAP925', 'MSH002', 'SON515',
                       'MWR705', 'MWR706', 'JAP831', 'MRK822', 'TIM463', 'AMB039', 'SRU130', 'JAP832', 'COK180', 'COK191', 'NLA006', 'COK211', 'COK340', 'MSH626', 'SON433', 'COK190')
                group by n.tech
                       , m.date
                       , n.site_id

                union

                select 'VoLTE'                                                           as tech
                     , m.date
                     , n.site_id

                     , sum(volte_traffic_erl)                                            as traffic
                     , sum(volte_dl_volume_qci1_mbyte) + sum(volte_ul_volume_qci1_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
                      ('NTK015', 'NTK073', 'COK059', 'BTI904', 'NTK068', 'TMR063', 'NTK081', 'NTK077', 'NTK047', 'COK036', 'NTK071', 'NTK002', 'NTK075', 'BTI905', 'COK188', 'NTK080', 'NAB205', 'TIM425', 'TUL219', 'NTK056', 'NTK079', 'NAB204', 'NTK082', 'NTK074', 'COK117', 'NTK067', 'TMB035',
                       'TMB171', 'TIM427', 'MSH629', 'TIM461', 'WRS112', 'MWR700', 'NLA383', 'MWR699', 'JAP830', 'SON523', 'BTI906', 'MSH630', 'BIA282', 'NAB211', 'BIA281', 'JAP823', 'AMB025', 'JAP827', 'NAB208', 'JAP826', 'NLA009', 'COK500', 'COK502', 'TIM462', 'NAB207', 'JAP828', 'NAB210',
                       'COK501', 'BTI907', 'MWR707', 'NAB209', 'WAM015', 'NAB029', 'MRK820', 'MRK821', 'KEP066', 'FFK159', 'BIA009', 'TIM183', 'AGA044', 'SON524', 'WRS113', 'WRS114', 'KMN060', 'JAP829', 'TMR064', 'COK503', 'SRU129', 'FFK360', 'AGA045', 'COK171', 'JAP925', 'MSH002', 'SON515',
                       'MWR705', 'MWR706', 'JAP831', 'MRK822', 'TIM463', 'AMB039', 'SRU130', 'JAP832', 'COK180', 'COK191', 'NLA006', 'COK211', 'COK340', 'MSH626', 'SON433', 'COK190')
                group by n.tech
                       , m.date
                       , n.site_id

                union

                select n.tech
                     , m.date
                     , n.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
                      ('NTK015', 'NTK073', 'COK059', 'BTI904', 'NTK068', 'TMR063', 'NTK081', 'NTK077', 'NTK047', 'COK036', 'NTK071', 'NTK002', 'NTK075', 'BTI905', 'COK188', 'NTK080', 'NAB205', 'TIM425', 'TUL219', 'NTK056', 'NTK079', 'NAB204', 'NTK082', 'NTK074', 'COK117', 'NTK067', 'TMB035',
                       'TMB171', 'TIM427', 'MSH629', 'TIM461', 'WRS112', 'MWR700', 'NLA383', 'MWR699', 'JAP830', 'SON523', 'BTI906', 'MSH630', 'BIA282', 'NAB211', 'BIA281', 'JAP823', 'AMB025', 'JAP827', 'NAB208', 'JAP826', 'NLA009', 'COK500', 'COK502', 'TIM462', 'NAB207', 'JAP828', 'NAB210',
                       'COK501', 'BTI907', 'MWR707', 'NAB209', 'WAM015', 'NAB029', 'MRK820', 'MRK821', 'KEP066', 'FFK159', 'BIA009', 'TIM183', 'AGA044', 'SON524', 'WRS113', 'WRS114', 'KMN060', 'JAP829', 'TMR064', 'COK503', 'SRU129', 'FFK360', 'AGA045', 'COK171', 'JAP925', 'MSH002', 'SON515',
                       'MWR705', 'MWR706', 'JAP831', 'MRK822', 'TIM463', 'AMB039', 'SRU130', 'JAP832', 'COK180', 'COK191', 'NLA006', 'COK211', 'COK340', 'MSH626', 'SON433', 'COK190')
                group by n.tech
                       , m.date
                       , n.site_id)

select tech
     , date
     , site_id
     , traffic
     , payload_mbyte
from master
order by tech, site_id, date
;


