oracle小记4
--客户合并跟踪列表SQL
--登录用户不同,显示的对方客户经理也不同
--发起方类型ccb.apply_type为 0 表示发起方客户经理(对方客户合并到本地客户) 1 对方客户经理(本地客户合并到对方客户)
select rownum as "index",a.*,
(select pb.name
from ec_org_person pb
where pb.manager_no =
(select case
when ccb.apply_type = '1' then
ccb.other_mgr_no
when ccb.apply_type = '0' and
ccb.other_mgr_no = scb.manager_no_one then
scb.manager_no_one
else mc.manager_no
end case
from b_oc_cust_combine ccb, b_oc_similar_cust scb,b_oc_manager_cust mc
where ccb.comb_no = "combineNum"
and ccb.similar_id = scb.similar_id
and scb.cust_no_two=mc.cust_no
and mc.manager_type='0')) as mgr
--如果ccb.apply_type=1,主管客户经理为ccb.other_mgr_no;如果为0,则若ccb.other_mgr_no = scb.manager_no_one,主管客户经理为scb.manager_no_one,否则为cust_no_two的主管客户经理
from (select combine_id as "combineId",
comb_no as "combineNum",
apply_date as "applyDate",
comb_status as "applyStatus",
cc.similar_id as "similarId",
cust_no_one as "custNum",
cust_name as "custName",
cert_type_one as "certType",
cert_no_one as "certNum",
d.name as "manageBranch",
pa.name as "tManagerName",
cc.apply_type as "apply_type"
from b_oc_cust_combine cc,
b_oc_similar_cust sc,
ec_org_person pa,
ec_org_department d,
b_oc_customer c
where cc.similar_id = sc.similar_id
and sc.cust_no_one = c.cust_no
and c.manage_branch = d.id
and cc.other_mgr_no = pa.manager_no
and cc.oper_mgr_no = 'MG0000000005'--一般情况申请人为本地客户主管客户经理,此处获得合并后的客户经理采用标志位apply_type判断是防止申请人为第三方
union
select combine_id as "combineId",
comb_no as "combineNum",
apply_date as "applyDate",
comb_status as "applyStatus",
cc.similar_id as "similarId",
cust_no_two as "custNum",
cust_name as "custName",
cert_type_two as "certType",
cert_no_two as "certNum",
d.name as "manageBranch",
pa.name as "tManagerName",
cc.apply_type as "apply_type"
from b_oc_cust_combine cc,
b_oc_similar_cust sc,
ec_org_person pa,
ec_org_department d,
b_oc_customer c
where cc.similar_id = sc.similar_id
and sc.cust_no_two = c.cust_no
and c.manage_branch = d.id
and sc.manager_no_one = pa.manager_no
and cc.other_mgr_no = 'MG0000000005')a
order by 3 desc--根据第三列排序