with master as (select m.date
                     , r.kota_kabupaten

                     , nds(sum(num_inter_handover_success_rate), sum(denum_inter_handover_success_rate))          as inter_handover_success_rate
                     , sum(number_of_sn_change_confirmations)                                                     as number_of_sn_change_confirmations
                     , sum(number_of_sn_change_requests)                                                          as number_of_sn_change_requests
                     , nds(sum(num_intra_handover_success_rate), sum(denum_intra_handover_success_rate))          as intra_handover_success_rate
                     , nds(sum(num_availability), count(*) * 60 * 60)                                             as availability
                     , nds(sum(number_of_times_that_an_sn_is_added_successfully), sum(number_of_sn_add_requests)) as setup_success_rate
                     , 100 - ndp(sum(num_nr_retainability), sum(denum_nr_retainability))                          as retainability
                     , sum(num_sn_setup_success_rate)                                                             as num_sn_setup_success_rate
                     , sum(num_intra_handover_success_rate)                                                       as num_intra_handover_success_rate
                     , sum(denum_intra_handover_success_rate)                                                     as denum_intra_handover_success_rate
                     , sum(num_inter_handover_success_rate)                                                       as num_inter_handover_success_rate
                     , sum(denum_inter_handover_success_rate)                                                     as denum_inter_handover_success_rate
                     , sum(num_nr_retainability)                                                                  as num_nr_retainability
                     , sum(denum_nr_retainability)                                                                as denum_nr_retainability
                     , sum(num_availability)                                                                      as num_availability
                     , avg(avg_rrc_user_number)                                                                   as avg_rrc_user_number
                     , max(max_rrc_user_number)                                                                   as max_rrc_user_number
                     , nds(sum(num_latency_dl), sum(denum_latency_dl))                                            as latency_dl
                     , nds(sum(num_latency_ul), sum(denum_latency_ul))                                            as latency_ul
                     , nds(sum(num_user_throughput_dl), sum(denum_user_throughput_dl))                            as user_throughput_dl
                     , nds(sum(num_user_throughput_ul), sum(denum_user_throughput_ul))                            as user_throughput_ul
                     , nds(sum(num_cell_throughput_dl), sum(denum_cell_throughput_dl_v2))                         as cell_throughput_dl
                     , nds(sum(num_cell_throughput_ul), sum(denum_cell_throughput_ul_v2))                         as cell_throughput_ul
                     , nds(sum(num_packet_loss), sum(denum_packet_loss))                                          as packet_loss
                     , sum(num_latency_dl)                                                                        as num_latency_dl
                     , sum(denum_latency_dl)                                                                      as denum_latency_dl
                     , sum(num_packet_loss)                                                                       as num_packet_loss
                     , sum(denum_packet_loss)                                                                     as denum_packet_loss
                     , sum(num_cell_throughput_dl)                                                                as num_cell_throughput_dl
                     , sum(num_cell_throughput_ul)                                                                as num_cell_throughput_ul
                     , sum(num_user_throughput_dl)                                                                as num_user_throughput_dl
                     , sum(denum_user_throughput_dl)                                                              as denum_user_throughput_dl
                     , sum(num_user_throughput_ul)                                                                as num_user_throughput_ul
                     , sum(denum_user_throughput_ul)                                                              as denum_user_throughput_ul
                     , sum(num_latency_ul)                                                                        as num_latency_ul
                     , sum(denum_latency_ul)                                                                      as denum_latency_ul
                     , avg(avg_active_user_number)                                                                as avg_active_user_number
                     , max(max_active_user_number)                                                                as max_active_user_number
                     , sum(payload)                                                                               as payload
                     , sum(payload_dl)                                                                            as payload_dl
                     , sum(payload_ul)                                                                            as payload_ul
                     , nds(sum(num_prb_utilization_ul), sum(denum_prb_utilization_ul))                            as prb_utilization_ul
                     , nds(sum(num_average_cqi), sum(denum_average_cqi))                                          as average_cqi
                     , nds(sum(num_prb_utilization_dl), sum(denum_prb_utilization_dl))                            as prb_utilization_dl
                     , sum(prb_ussage_ul)                                                                         as prb_ussage_ul
                     , nds(sum(num_average_cqi_64_qam), sum(denum_average_cqi_64_qam))                            as average_cqi_64_qam
                     , nds(sum(num_average_cqi_256_qam), sum(denum_verage_cqi_256_qam))                           as average_cqi_256_qam
                     , nds(sum(num_spectrum_eff), sum(denum_spectrum_eff))                                        as spectrum_eff
                     , sum(num_average_cqi)                                                                       as num_average_cqi
                     , sum(denum_average_cqi)                                                                     as denum_average_cqi
                     , sum(num_average_cqi_64_qam)                                                                as num_average_cqi_64_qam
                     , sum(denum_average_cqi_64_qam)                                                              as denum_average_cqi_64_qam
                     , sum(num_average_cqi_256_qam)                                                               as num_average_cqi_256_qam
                     , sum(denum_verage_cqi_256_qam)                                                              as denum_verage_cqi_256_qam
                     , sum(num_spectrum_eff)                                                                      as num_spectrum_eff
                     , sum(denum_spectrum_eff)                                                                    as denum_spectrum_eff
                     , sum(num_prb_utilization_dl)                                                                as num_prb_utilization_dl
                     , sum(denum_prb_utilization_dl)                                                              as denum_prb_utilization_dl
                     , sum(num_prb_utilization_ul)                                                                as num_prb_utilization_ul
                     , sum(denum_prb_utilization_ul)                                                              as denum_prb_utilization_ul
                     , sum(avr_ta)                                                                                as avr_ta
                     , avg(avg_uplink_interference)                                                               as avg_uplink_interference
                     , max(max_uplink_interference)                                                               as max_uplink_interference
                     , sum(prb_ussage_dl)                                                                         as prb_ussage_dl
                     , sum(number_of_bytes_of_ul_pdcp_services_mbyte)                                             as number_of_bytes_of_ul_pdcp_services_mbyte
                     , sum(number_of_bytes_of_dl_pdcp_services_mbyte)                                             as number_of_bytes_of_dl_pdcp_services_mbyte

                from r11.meas_5g_daily m
                         join network_cell n on m.network_cell_id = n.id
                         join ref_site r on n.site_id = r.site_id

                where m.date between date_int(1) and date_int(1)
--                   and n.region = 'PUMA'
--                   and n.site_id in ('AMB002')

                group by m.date
                       , r.kota_kabupaten)
select *
from master
order by kota_kabupaten, date