You are on page 1of 2

create table pxl_temp.

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)
)

create table pxl_temp.adhoc_Report_fraud_team_23032023_customer_group


as (
select distinct t2.acct_id,t1.cust_id,t3.cust_catg as customer_group,
(select
concat(a, b, c, d, e, f, g, h, i, j, k, l) as account_group
from
(
select
case
when t2.cc_account = 1 then 'cc_account,'
end as a,
case
when t2.ci_account = 1 then 'ci_account,'
end as b,
case
when t2.b_group_dunning = 1 then 'b_group_dunning,'
end as c,
case
when t2.b_group_no_dunning = 1 then 'b_group_no_dunning,'
end as d ,
case
when t2.erecharge = 1 then 'erecharge,'
end as e ,
case
when t2.vip = 1 then 'vip,'
end as f ,
case
when t2.vvip = 1 then 'vvip,'
end as g ,
case
when t2.upfront = 1 then 'upfront,'
end as h ,
case
when t2.employee = 1 then 'employee,'
end as i ,
case
when t2.staff = 1 then 'staff,'
end as j ,
case
when t2.government = 1 then 'government,'
end as k ,
case
when t2.individual = 1 then 'individual'
end as l )as foo)
from pxl_temp.adhoc_Report_fraud_team_23032023 t1
left join pxl_staging.acct_group t2 on t1.acct_id=t2.acct_id
left join pxl_staging.account_catg t3 on t1.acct_id=t3.acct_id and
t1.cust_id=t3.cust_id)

select * from pxl_temp.adhoc_Report_fraud_team_23032023_balance

select * from pxl_raw.pmt_abc_bill pab

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

You might also like