desktop_task_schedule/code/db/续保带坐席工号.sql

513 lines
22 KiB
MySQL
Raw Permalink Normal View History

2023-04-04 09:58:05 +00:00
--execute clean_mensual_renewal;
INSERT INTO desktop_archievement_admin.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD>
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>,
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(to_char(SYSDATE,
'yyyy-mm') || '-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>,
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>,
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(to_char(SYSDATE,
'yyyy-mm') || '-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>,
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>,
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>
AND dqs.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = yxb.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
COMMIT;