You are on page 1of 2

with tmp_acct1 as

(select t1.acct_id, 'CI Account,' attr


from mig_mid_acct t1, mig_mid_cust t2, mig_mid_ACCOUNT_MANAGER_CUST t3
where t1.cust_id = t2.cust_id
and t1.acct_id = t3.acct_id
and t1.cust_id = t3.cust_id
and t1.acct_id = t3.acct_id
and t2.cust_type = 'A'

),
tmp_acct2 as
(select t1.acct_id, 'Individual Account,' attr
from mig_mid_acct t1, mig_mid_cust t2
where t1.cust_id = t2.cust_id
and t2.cust_type = 'A'
and (t1.acct_id, t2.cust_id) not in
(select acct_id, cust_id from mig_mid_ACCOUNT_MANAGER_CUST)),

tmp_acct3 as
(select acct_id,
listagg(t2.catg_name, ',') within group(order by acct_id) attr
from mig_mid_scatter_acct_catg t1, catg@link_to_cc t2
where t1.acct_catg_id = t2.catg_id
group by acct_id),

tmp_acct4 as
(select acct_id, 'Auto Debit Account' attr
from mig_mid_acct
where PAYMENT_TYPE = 'A'
and STATE = 'A')

select /*+ parallel(8)*/


a.subs_id,
a.prefix || a.acc_nbr MSISDN,
g.offer_name RATE_PLAN,
d.prod_state_name subs_status,
c.acct_nbr,
c.acct_id customer_id_legacy_BSCS,
decode(c.state, 'A', 'Active', 'X', 'Inactive') acct_status,
i.billing_cycle_type_name,
e.cust_id customer_code_aicrm,
h.cert_type_name,
decode(e.net_type, 'S', 'Y', 'N') cust_test_flag,
decode(e.cust_flag, 'V', 'Y', 'N') cust_verified_flag,

k.attr || L.attr || n.attr || m.attr Account_Group,

c.acct_name Account_name,
Case
when j.subs_id is not null then
'Principal'
when j.subs_id is null then
'Member'
end Member_Flag
from mig_mid_acct c,
mig_mid_subs a,
mig_mid_prod b,
prod_state@link_to_cc d,
mig_mid_cust e,
mig_mid_cert f,
offer@link_to_cc g,
cert_type@link_to_cc h,
billing_cycle_type@link_to_cc i,

(select t1.subs_id, t2.value


from mig.mig_mid_subs_rela t1, mig.mig_mid_subs_rela_attr_value t2
where attr_id = 100788
and t1.subs_rela_id = t2.subs_rela_id) j,

tmp_acct1 k,
tmp_acct2 L,
tmp_acct3 m,
tmp_acct4 n

where c.acct_id = a.acct_id(+)


and nvl(c.payment_comments, 'mig') <> 'mig: starter pack'
and a.subs_id = b.prod_id(+)
and b.prod_state = d.prod_state(+)
and (a.acc_nbr not like 'BUND%' or a.acc_nbr is null)
and c.cust_id = e.cust_id
and e.cert_id = f.cert_id
and f.cert_type_id = h.cert_type_id
and b.subs_plan_id = g.offer_id(+)
and c.billing_cycle_type_id = i.billing_cycle_type_id
and b.prod_state <> 'B'
and a.subs_id = j.subs_id(+)
and c.acct_id = k.acct_id(+)
and c.acct_id = L.acct_id(+)
and c.acct_id = m.acct_id(+)
and c.acct_id = n.acct_id(+)

You might also like