with sector_level as (select raw.yearweek                                                                    as weekly
                           , n.site_id
                           , n.sector
                           , n.band

                           , ndp(sum(num_dl_prb_utilization_percent), sum(denum_dl_prb_utilization_percent)) as dl_prb_utilization
                           , ndp(sum(num_ul_prb_utilization_percent), sum(denum_ul_prb_utilization_percent)) as ul_prb_utilization

                      from r11.meas_4g_daily_bh_activeuser raw
                               join network_cell n on raw.network_cell_id = n.id
                      where date between '2023-12-01' and '2023-12-07'
                      group by raw.yearweek
                             , n.site_id
                             , n.sector
                             , n.band
                      order by site_id, sector, weekly)
select weekly
     , site_id
     , sector
     , avg(case when band = 'LTE900' then dl_prb_utilization end)     as LTE900
     , avg(case when band = 'LTE1800' then dl_prb_utilization end)    as LTE1800
     , avg(case when band = 'LTE2100' then dl_prb_utilization end)    as LTE2100
     , avg(case when band = 'LTE2300 F1' then dl_prb_utilization end) as LTE2300_F1
     , avg(case when band = 'LTE2300 F2' then dl_prb_utilization end) as LTE2300_F2
     , avg(case when band = 'LTE2300 F3' then dl_prb_utilization end) as LTE2300_F3
     , max(dl_prb_utilization)                                        as max_prb
     , min(dl_prb_utilization)                                        as min_prb
     , max(dl_prb_utilization) - min(dl_prb_utilization)              as delta_prb
     , case
           when max(dl_prb_utilization) - min(dl_prb_utilization) > 50 then '>50%'
           when max(dl_prb_utilization) - min(dl_prb_utilization) < 30 then 'balance'
           else '30-50%' end                                          as remark
from sector_level
group by weekly, site_id, sector
order by site_id, sector, weekly
;