Professional Documents
Culture Documents
004 Fraud Victims Query1
004 Fraud Victims Query1
adhoc_Report_fraud_team_23032023 as (
with
device_agreement as
( select *,
row_number() over (partition by subs_id order by
agreement_eff_date) as row_num
from pxl_raw.cc_cc_agreement_inst where agreement_type in ('PHONE_CONTRACT')
)
select t3.cust_id,t3.acct_id,t2.catg_name,t3.msisdn,t3.acct_nbr as
account_no,t3.subs_plan_id,t5.offer_name,
t4.prod_state_name,t6.agreement_name,t3.cust_name,t3.cert_nbr
from pxl_raw.cc_cc_scatter_subs_catg t1
join pxl_raw.cc_cc_catg t2 on t1.subs_catg_id =t2.catg_id
join pxl_staging.daily_subscriber_info_ext t3 on t1.subs_id =t3.subs_id
join pxl_raw.cc_cc_prod_state t4 on t4.prod_state =t3.prod_state
join pxl_raw.cc_crm_offer t5 on t5.offer_id =t3.subs_plan_id
left join ( select * from device_agreement where row_num = 1) t6 on t6.subs_id =
t1.subs_id and t6.cust_id=t3.cust_id
where subs_catg_id in (-234,-235,-236)
)
select t1.subs_id,t1.catg_name,t1.msisdn,t1.account_no,t1.offer_name as
Rate_plan,t1.prod_state_name as status,t1.agreement_name,t1.cust_name,t1.cert_nbr
as ID,t2.customer_group,account_group,
coalesce(t3.Outstanding_Balance, 0) as Outstanding_Balance from
pxl_temp.adhoc_Report_fraud_team_23032023 t1
left join pxl_temp.adhoc_Report_fraud_team_23032023_customer_group t2
on t2.acct_id=t1.acct_id and t2.cust_id=t1.cust_id
left join pxl_temp.adhoc_Report_fraud_team_23032023_balance t3 on
t3.acct_id=t1.acct_id