From 21ffcaeab896c3b7a3b0292b8efefd80c543dff5 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Fri, 31 Mar 2023 09:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=94=9F=E6=88=90=E7=BB=AD?= =?UTF-8?q?=E4=BF=9D=E6=95=B0=E6=8D=AE=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/db/续保.sql | 183 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 code/db/续保.sql diff --git a/code/db/续保.sql b/code/db/续保.sql new file mode 100644 index 0000000..e079732 --- /dev/null +++ b/code/db/续保.sql @@ -0,0 +1,183 @@ +with cc as( +select pt.policy_no policy_no,sum(pt.premium_amount )premium_amount,sum(pt.tax_amount) tax_amount from idst0.auto_premium_t pt group by pt.policy_no +) + + +,bb as (select +t.policy_no , +(case + when e.product_code like '1102%' and e.product_code not like '110224%' and e.product_code !='11026000'then 'ձ' + when e.product_code like '1101%' or e.product_code like '1301%' or e.product_code like '11110000%' then 'Ʋ' + when e.product_code like '1107%' or e.product_code like '1307%' or e.product_code like '1304A400%' then '' + when e.product_code like '1106%' or e.product_code like '51015700' then 'Ҳ' + when (e.product_code like '1104%' or e.product_code like '1204%' or e.product_code like '13040000%') and e.product_code not like '120404%' then '' + when e.product_code like '1203%' or e.product_code like '1103%' or e.product_code like '120404%' then '' + when e.product_code like '1305%' then '' + when e.product_code like '111%' and e.product_code not like '11110000%' then 'ũҵ' + when e.product_code like '1109%' or e.product_code like '1309%' then '֤' + when e.product_code like '1312%' then '' + when e.product_code like '1308%' then '' + when e.product_code like '23%' then '' + when e.product_code like '22%' then '' + when e.product_code like '110224%'or e.product_code='11026000' then 'ǿ' +else 'δ' end) as ִ + from +idst0.auto_agreement_request_t t +left join idst0.auto_agreement_t e on e.policy_no = t.policy_no +) + +, aa1 as (select +a.policy_no ɱ +,a.selling_shop_code ̴ +,a.planned_end_date ʱ +,case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then 'רҵһ' + when a.planned_end_date > to_date('2023-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and (a.selling_shop_code||a.tel_sale_4s_code IN ('00EA','00F1','00G9')) then 'רҵһ' + else nvl(dt.,z.section_office_name) end +,(case when to_number(to_char(a.planned_end_date,'yyyy'))='2023' and nvl(dt.,y.department_name) not like '֧˾' andcd.memo like '%%' or cd.memo like '%%' and v.vehicle_brand in ('˹','ε','','С','','','AITO','ARCFOX', '˹й', '˹(й)') AND v.vin not in ('LJ1E6A2UXL7744108','LW433B10XL1001411','LJ1E6A3U2L7742089','L1NSPGHB0MA002652') THEN 'Դҵչŷ' + when (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end)='֧˾' + then (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end ) +when cd.memo like '%%'or cd.memo like '%%' then 'ҵ' + when a.planned_end_date > to_date('2023-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and (a.selling_shop_code||a.tel_sale_4s_code IN ('00EA','00F1','00G9')) then '֧ͬ˾' + else (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end) end) β +,qa.USAGE_XM ʹ +,decode(qa.bd_type,'1','ǿ','2','ҵ','3','̹','') +,(case when (qa.bd_type='1' and nt.ecompensation_rate>1) then '' end ) Ԥ +,x.staff_name as +,bb.ִ +,cc.signature_date ±ǩʱ +,(select hmd.ܿ from (select distinct * from dc_lsj_xb_hmd) hmd where hmd.vin=v.vin) ܿ + +from +idst0.auto_agreement_t a +left join bb on bb.=a.policy_no +left join ywglxt.w_dxbd_i i on a.policy_no = i.bdh +left join idst0.motorised_vehicle_t v on a.policy_no=v.policy_no +left join ywglxt.q_auto_agreement_t qa on qa.policy_no=a.policy_no + +left join idst0.auto_new_product_info_t nt on nt.policy_no=a.policy_no and nt.endorsement_no='' +left join idst0.rydm_t x on x.staff_code = nvl(upper(i.zhjywy),a.operator_code) +left join idst0.bm_t y on x.department_code = y.department_code +left join idst0.ks_t z on x.section_office_code = z.section_office_code +left join cc pt on pt.policy_no=a.policy_no +left join +(select distinct aa.policy_no, + vv.vin,aa.inception_date,t.signature_date,(pt.premium_amount - nvl(pt.tax_amount,0)) qdbf, + (case when aa.inception_date - aa.issue_date >= '30' then vv.vin end) if30 ,bb.ִ + from idst0.auto_agreement_t aa + left join bb on bb.=aa.policy_no + left join idst0.motorised_vehicle_t vv on vv.policy_no = aa.policy_no + left join idst0.auto_agreement_request_t t on t.policy_no = aa.policy_no and t.endorsement_no = '' + left join idst0.auto_premium_t pt on pt.policy_no = aa.policy_no and pt.endorsement_no = '' + where aa.policy_no=vv.policy_no and aa.policy_status = '1' --and aa.product_code not in ('11022400','11023900','11024000','11024600','11026000') + and aa.branch_company_code = '3080100'and (pt.premium_amount - nvl(pt.tax_amount,0))>100 + and aa.inception_date >= to_date('2022-12-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + and aa.inception_date < to_date('2023-11-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + and aa.branch_company_code = vv.branch_company_code +) cc on (cc.vin = v.vin and cc.ִ=bb.ִ) and cc.inception_date > a.planned_end_date-30 --ʱƷſΪ30 +left join dc_yangg_cx_dianxiaodoudi cd on cd.policy_no = a.policy_no +left join dc_tb_jc_c_tag dt on dt.=a.policy_no +left join idst0.auto_agreement_t aa on aa.policy_no= cc.policy_no +left join cc pt1 on pt1.policy_no=aa.policy_no +where a.policy_status = '1' and a.planned_end_date-a.inception_date>270 and + a.planned_end_date >= to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') +and a.planned_end_date < to_date('2023-10-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) +, aa2 as (select +a.policy_no ɱ +,a.selling_shop_code ̴ +,a.planned_end_date ʱ +,case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then 'רҵһ' + when a.planned_end_date > to_date('2023-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and (a.selling_shop_code||a.tel_sale_4s_code IN ('00EA','00F1','00G9')) then 'רҵһ' + else nvl(dt.,z.section_office_name) end +,(case when to_number(to_char(a.planned_end_date,'yyyy'))='2023' and nvl(dt.,y.department_name) not like '֧˾' andcd.memo like '%%' or cd.memo like '%%' and v.vehicle_brand in ('˹','ε','','С','','','AITO','ARCFOX', '˹й', '˹(й)') AND v.vin not in ('LJ1E6A2UXL7744108','LW433B10XL1001411','LJ1E6A3U2L7742089','L1NSPGHB0MA002652') THEN 'Դҵչŷ' + when (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end)='֧˾' + then (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end ) +when cd.memo like '%%'or cd.memo like '%%' then 'ҵ' + when a.planned_end_date > to_date('2023-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and (a.selling_shop_code||a.tel_sale_4s_code IN ('00EA','00F1','00G9')) then '֧ͬ˾' + else (case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '֧˾' else nvl(dt.,y.department_name) end) end) β +,qa.USAGE_XM ʹ +,decode(qa.bd_type,'1','ǿ','2','ҵ','3','̹','') +,(case when (qa.bd_type='1' and nt.ecompensation_rate>1) then '' end ) Ԥ +,x.staff_name as +,bb.ִ +,cc.signature_date ±ǩʱ +,(select hmd.ܿ from (select distinct * from dc_lsj_xb_hmd) hmd where hmd.vin=v.vin) ܿ + +from +idst0.auto_agreement_t a +left join bb on bb.=a.policy_no +left join ywglxt.w_dxbd_i i on a.policy_no = i.bdh +left join idst0.motorised_vehicle_t v on a.policy_no=v.policy_no +left join ywglxt.q_auto_agreement_t qa on qa.policy_no=a.policy_no +left join idst0.auto_new_product_info_t nt on nt.policy_no=a.policy_no and nt.endorsement_no='' +left join idst0.rydm_t x on x.staff_code = nvl(upper(i.zhjywy),a.operator_code) +left join idst0.bm_t y on x.department_code = y.department_code +left join idst0.ks_t z on x.section_office_code = z.section_office_code +left join cc pt on pt.policy_no=a.policy_no +left join +(select distinct aa.policy_no, + vv.vin,aa.inception_date,t.signature_date,(pt.premium_amount - nvl(pt.tax_amount,0)) qdbf, + (case when aa.inception_date - aa.issue_date >= '30' then vv.vin end) if30 ,bb.ִ + from idst0.auto_agreement_t aa + left join bb on bb.=aa.policy_no + left join idst0.motorised_vehicle_t vv on vv.policy_no = aa.policy_no + left join idst0.auto_agreement_request_t t on t.policy_no = aa.policy_no and t.endorsement_no = '' + left join idst0.auto_premium_t pt on pt.policy_no = aa.policy_no and pt.endorsement_no = '' + where aa.policy_no=vv.policy_no and aa.policy_status = '1' --and aa.product_code not in ('11022400','11023900','11024000','11024600','11026000') + and aa.branch_company_code = '3080100'and (pt.premium_amount - nvl(pt.tax_amount,0))>100 + and aa.inception_date >= to_date('2022-12-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + and aa.inception_date < to_date('2023-11-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + and aa.branch_company_code = vv.branch_company_code +) cc on (cc.vin = v.vin and cc.ִ=bb.ִ) and cc.inception_date > a.planned_end_date-30 --ʱƷſΪ30 +left join dc_yangg_cx_dianxiaodoudi cd on cd.policy_no = a.policy_no +left join dc_tb_jc_c_tag dt on dt.=a.policy_no +left join idst0.auto_agreement_t aa on aa.policy_no= cc.policy_no +left join cc pt1 on pt1.policy_no=aa.policy_no +where a.policy_status = '1' and a.planned_end_date-a.inception_date>270 and + a.planned_end_date >= to_date('2023-10-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') +and a.planned_end_date < to_date('2024-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) + +,aa3 as (select distinct * from aa1 +union all +(select distinct * from aa2) ) + +,AA AS (SELECT AA3.* +,nvlzx.workerno,et.telpartnercode) ϯ +,(case when nvlzx.workerno,et.telpartnercode) = 'DX001' and aa3. like '%%' then 'ΰ' +when nvlzx.workerno,et.telpartnercode) = 'DX001' and aa3. not like '%%' then '' +else to_char(ys.ϯ) END) ϯ +,YS.Ŷ ϯŶ +FROM AA3 +left join idst0.auto_agreement_extend_t et on et.policy_no = AA3.ɱ +left join idst0.t_sell_policy_autobase_t zx on zx.policy_no = AA3.ɱ +left join dc_YZH_ZXYS YS ON YS.ϯ= nvlzx.workerno,et.telpartnercode)) + +, yxb as( +--- +select +aa.β +,aa.,aa.,aa.ϯŶ,aa.ϯ, +--(case when a.ʶ=''and A.β='ҵ' then 'ҵ' else A. end) , +(case when count(1) is null then 0 else count(1) end) ۼ + from aa +where +aa.ʹ in ('ͥó','ҵͳ') and aa.Ԥ is null and aa.ܿ is null and aa. in '̹','ǿ' +and aa.ʱ >=to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND aa.ʱ=to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND aa.ʱ