select
    b.organ_code
     , b.organ_name
     , b.comm_id
     , b.comm_name
     , sum(case when FeesDueDate < '2024-01-01' then ChargeAmount else 0 end) pr_paid_amt
     , sum(case when FeesDueDate >= '2024-01-01' and FeesDueDate < '2025-01-01' then ChargeAmount else 0 end) cu_paid_amt
     , sum(case when FeesDueDate >= '2025-01-01' then ChargeAmount else 0 end) fu_paid_amt
from dwd_finance_today_fees_d a
         left join (select distinct organ_code, organ_name, comm_id, comm_name from dim_organ_mapping) b
                   on a.CommID = b.comm_id
group by
    b.organ_code
       , b.organ_name
       , b.comm_id
       , b.comm_name