desktop_task_schedule/code/db/续保.sql

184 lines
12 KiB
MySQL
Raw Permalink Normal View History

2023-03-31 01:05:50 +00:00
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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
(case
when e.product_code like '1102%' and e.product_code not like '110224%' and e.product_code !='11026000'then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1101%' or e.product_code like '1301%' or e.product_code like '11110000%' then '<EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1107%' or e.product_code like '1307%' or e.product_code like '1304A400%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1106%' or e.product_code like '51015700' then '<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD>'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1203%' or e.product_code like '1103%' or e.product_code like '120404%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1305%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '111%' and e.product_code not like '11110000%' then 'ũҵ<EFBFBD><EFBFBD>'
when e.product_code like '1109%' or e.product_code like '1309%' then '<EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1312%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '1308%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '23%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '22%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
when e.product_code like '110224%'or e.product_code='11026000' then '<EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD>'
else 'δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' end) as <EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>
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 <EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD>
,a.selling_shop_code <EFBFBD><EFBFBD><EFBFBD>̴<EFBFBD><EFBFBD><EFBFBD>
,a.planned_end_date <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
,case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>רҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>רҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>'
else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,z.section_office_name) end <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,(case when to_number(to_char(a.planned_end_date,'yyyy'))='2023' and nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) not like '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' and<EFBFBD><EFBFBD>cd.memo like '%<25><><EFBFBD><EFBFBD>%' or cd.memo like '%<25><><EFBFBD><EFBFBD>%' <EFBFBD><EFBFBD>and v.vehicle_brand in ('<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD>','ε<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','С<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','AITO','ARCFOX<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD>(<28>й<EFBFBD>)') AND v.vin not in ('LJ1E6A2UXL7744108','LW433B10XL1001411','LJ1E6A3U2L7742089','L1NSPGHB0MA002652') THEN '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end)='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end )
when <EFBFBD><EFBFBD>cd.memo like '%<25><><EFBFBD><EFBFBD>%'or cd.memo like '%<25><><EFBFBD><EFBFBD>%'<EFBFBD><EFBFBD> then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
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 'ͬ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end) end) <EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>
,qa.USAGE_XM ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,decode(qa.bd_type,'1','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ','2','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ','3','<EFBFBD><EFBFBD><EFBFBD>̹<EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>') <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,(case when (qa.bd_type='1' and nt.ecompensation_rate>1) then '<EFBFBD><EFBFBD>' end ) <EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
,x.staff_name as <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,bb.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>
,cc.signature_date <EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
,(select hmd.<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> from (select distinct * from dc_lsj_xb_hmd) hmd where hmd.vin=v.vin) <EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
from
idst0.auto_agreement_t a
left join bb on bb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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='<EFBFBD><EFBFBD>'
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.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>
from idst0.auto_agreement_t aa
left join bb on bb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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 = '<EFBFBD><EFBFBD>'
left join idst0.auto_premium_t pt on pt.policy_no = aa.policy_no and pt.endorsement_no = '<EFBFBD><EFBFBD>'
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.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>=bb.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>) and cc.inception_date > a.planned_end_date-30 --ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒſ<EFBFBD>Ϊ30<EFBFBD><EFBFBD>
left join dc_yangg_cx_dianxiaodoudi cd on cd.policy_no = a.policy_no
left join dc_tb_jc_c_tag dt on dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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 <EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD>
,a.selling_shop_code <EFBFBD><EFBFBD><EFBFBD>̴<EFBFBD><EFBFBD><EFBFBD>
,a.planned_end_date <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
,case when to_number(to_char(a.planned_end_date,'yyyy'))='2022' and a.selling_shop_code||a.tel_sale_4s_code='00GK' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>רҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>רҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>'
else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,z.section_office_name) end <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,(case when to_number(to_char(a.planned_end_date,'yyyy'))='2023' and nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) not like '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' and<EFBFBD><EFBFBD>cd.memo like '%<25><><EFBFBD><EFBFBD>%' or cd.memo like '%<25><><EFBFBD><EFBFBD>%' <EFBFBD><EFBFBD>and v.vehicle_brand in ('<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD>','ε<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','С<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','AITO','ARCFOX<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD>(<28>й<EFBFBD>)') AND v.vin not in ('LJ1E6A2UXL7744108','LW433B10XL1001411','LJ1E6A3U2L7742089','L1NSPGHB0MA002652') THEN '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end)='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end )
when <EFBFBD><EFBFBD>cd.memo like '%<25><><EFBFBD><EFBFBD>%'or cd.memo like '%<25><><EFBFBD><EFBFBD>%'<EFBFBD><EFBFBD> then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
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 'ͬ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾'
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 '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>˾' else nvl(dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,y.department_name) end) end) <EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>
,qa.USAGE_XM ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,decode(qa.bd_type,'1','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ','2','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ','3','<EFBFBD><EFBFBD><EFBFBD>̹<EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>') <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,(case when (qa.bd_type='1' and nt.ecompensation_rate>1) then '<EFBFBD><EFBFBD>' end ) <EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
,x.staff_name as <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,bb.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>
,cc.signature_date <EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
,(select hmd.<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> from (select distinct * from dc_lsj_xb_hmd) hmd where hmd.vin=v.vin) <EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
from
idst0.auto_agreement_t a
left join bb on bb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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='<EFBFBD><EFBFBD>'
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.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>
from idst0.auto_agreement_t aa
left join bb on bb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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 = '<EFBFBD><EFBFBD>'
left join idst0.auto_premium_t pt on pt.policy_no = aa.policy_no and pt.endorsement_no = '<EFBFBD><EFBFBD>'
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.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>=bb.<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>) and cc.inception_date > a.planned_end_date-30 --ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒſ<EFBFBD>Ϊ30<EFBFBD><EFBFBD>
left join dc_yangg_cx_dianxiaodoudi cd on cd.policy_no = a.policy_no
left join dc_tb_jc_c_tag dt on dt.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=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.*
,nvl<EFBFBD><EFBFBD>zx.workerno,et.telpartnercode) <EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,(case when nvl<EFBFBD><EFBFBD>zx.workerno,et.telpartnercode) = 'DX001' and aa3.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> like '%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%' then '<EFBFBD><EFBFBD>ΰ<EFBFBD><EFBFBD>'
when nvl<EFBFBD><EFBFBD>zx.workerno,et.telpartnercode) = 'DX001' and aa3.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> not like '%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
else to_char(ys.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>) END) <EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,YS.<EFBFBD>Ŷ<EFBFBD> <EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>
FROM AA3
left join idst0.auto_agreement_extend_t et on et.policy_no = AA3.<EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD>
left join idst0.t_sell_policy_autobase_t zx on zx.policy_no = AA3.<EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD>
left join dc_YZH_ZXYS YS ON YS.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>= nvl<EFBFBD><EFBFBD>zx.workerno,et.telpartnercode))
, yxb as(
---<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
select
aa.<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
--(case when a.<EFBFBD><EFBFBD>ʶ='<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'and A.<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>='<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' then '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>' else A.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> end) <EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
(case when count(1) is null then 0 else count(1) end) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
from aa
where
aa.ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> in ('<EFBFBD><EFBFBD>ͥ<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>','<EFBFBD><EFBFBD>ҵ<EFBFBD>ͳ<EFBFBD>') and aa.<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD> is null and aa.<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> is null and aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> in <EFBFBD><EFBFBD>'<EFBFBD><EFBFBD><EFBFBD>̹<EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ'<EFBFBD><EFBFBD>
and aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> >=to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><to_date(to_char(sysdate-1,'yyyy-mm-dd')||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
AND aa.<EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><=to_date(to_char(sysdate-1,'yyyy-mm-dd')||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
group by aa.<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<EFBFBD>ۼ<EFBFBD>/<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<EFBFBD>ۼ<EFBFBD>
,dqs AS(
---<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
select
aa.<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
(case when count(1) is null then 0 else count(1) end) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
from aa
where
aa.ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> in ('<EFBFBD><EFBFBD>ͥ<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>','<EFBFBD><EFBFBD>ҵ<EFBFBD>ͳ<EFBFBD>') and aa.<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD> is null and aa.<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> is null and aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> in <EFBFBD><EFBFBD>'<EFBFBD><EFBFBD><EFBFBD>̹<EFBFBD><EFBFBD><EFBFBD>','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ'<EFBFBD><EFBFBD>
and aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> >=to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><to_date(to_char(sysdate-1,'yyyy-mm-dd')||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
group by aa.<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,aa.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
)
select dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,dqs.<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,dqs.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,yxb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>,dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
from yxb,
dqs--,sdqs,syxs,cyxs,cdqs
where dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>= yxb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> AND dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>= yxb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> AND dqs.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>= yxb.<EFBFBD><EFBFBD><EFBFBD><EFBFBD> AND dqs.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>= yxb.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>