sel 202101 as calendar_year_month_id, base.source_system, count(distinct churn.source_Customer_id) churns, count(distinct base.source_Customer_id) base_count, churns*100.00/base_count||' %' as Churn_Rate from ( sel * from xyz.Customer_Base where calendar_date between '2021-01-01' and '2021-01-31' and Customer_Type_Group_Name <>'Mobile Prepaid' and source_system ='Voda' ) base left join ( sel churn.* ,'SUN' as source_system_der from xyz.Customer_Churn churn inner join product_grouping dpg on dpg.product_id=churn.bundle_id_pre and dpg.mark_group <> 'Mobile Prepaid' and churn.source_system= 'Voda' and actual_date between '2021-01-01' and '2021-02-01' ) churn on extract(year from churn.actual_date) = extract(year from base.calendar_date) and extract(month from churn.actual_date) = extract(month from base.calendar_date) and trim(churn.source_Customer_id) = trim(base.source_Customer_id) and churn.source_system_der = base.source_system where 1=1 group by 1,2