desktop_task_schedule/code/db/车非基础数据.sql

310 lines
11 KiB
MySQL
Raw Normal View History

2023-06-04 11:11:44 +00:00
INSERT INTO desktop_archievement_admin.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD>
WITH aa AS
(SELECT to_char(t.signature_date,
'yyyy-mm-dd') ǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
(to_char(T.signature_date,
'yyyy')) the_year,
(to_char(T.signature_date,
'mm')) the_month,
t.policy_no bdh,
t.endorsement_no pdh,
qt.t_cre tid,
QT.B_CRE BTID, -----<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
e.inception_date qbsj,
e.planned_end_date zzsj,
pt.premium_amount - nvl(pt.tax_amount,
0) bf
--,qt.qdbf - nvl(qt.qdbf_tax_amount,0) bf
,
nt.ecompensation_rate * (pt.premium_amount - nvl(pt.tax_amount,
0)) fxbf,
z.department_name bm,
z.department_code bmdm,
CASE
WHEN (et.telpartnercode LIKE '%HC%' OR
zx.workerno IN (SELECT code
FROM datacenter.dc_lsj_zx_hc)) THEN
'<EFBFBD><EFBFBD><EFBFBD>׷ῥ'
ELSE
''
END <EFBFBD>Ƿ<EFBFBD><EFBFBD>,
nvl(zx.workerno,
et.telpartnercode) <EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
(CASE
2023-03-10 09:32:13 +00:00
WHEN nvl(zx.workerno,
et.telpartnercode) = 'DX001' AND
xx.staff_name LIKE '%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%' THEN
'<EFBFBD><EFBFBD>ΰ<EFBFBD><EFBFBD>'
WHEN nvl(zx.workerno,
et.telpartnercode) = 'DX001' AND
xx.staff_name NOT LIKE '%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%' THEN
'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
ELSE
to_char(ys.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
2023-06-04 11:11:44 +00:00
END) <EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
YS.<EFBFBD>Ŷ<EFBFBD> <EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,
nvl(YS.<EFBFBD>Ŷ<EFBFBD>,
y.section_office_name) <EFBFBD><EFBFBD><EFBFBD><EFBFBD>N,
nvl((CASE
WHEN nvl(zx.workerno,
et.telpartnercode) = 'DX001' AND
xx.staff_name LIKE '%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%' THEN
'<EFBFBD><EFBFBD>ΰ<EFBFBD><EFBFBD>'
WHEN nvl(zx.workerno,
et.telpartnercode) = 'DX001' AND
xx.staff_name 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),
xx.staff_name) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>N
FROM idst0.auto_agreement_request_t t
LEFT JOIN idst0.auto_agreement_t e
ON e.policy_no = t.policy_no
LEFT JOIN idst0.motorised_vehicle_t v
ON v.policy_no = e.policy_no
LEFT JOIN idst0.auto_premium_t pt
ON pt.policy_no = t.policy_no
AND pt.endorsement_no = t.endorsement_no
LEFT JOIN ywglxt.w_dxbd_i i
ON e.policy_no = i.bdh
LEFT JOIN idst0.rydm_t xx
ON xx.staff_code = nvl(i.zhjywy,
e.operator_code)
LEFT JOIN idst0.ks_t y
ON y.section_office_code = nvl(xx.section_office_code,
e.section_office_code)
LEFT JOIN idst0.bm_t z
ON z.department_code = nvl(xx.department_code,
e.department_code)
--left join datacenter.dc_cx_csteam ct on ct.jbrcode = xx.staff_code
LEFT JOIN idst0.auto_new_product_info_t nt
ON nt.policy_no = t.policy_no
AND nt.endorsement_no = t.endorsement_no
--left join ywglxt.q_auto_agreement_extend_t qe on qe.policy_no = e.policy_no
LEFT JOIN ywglxt.q_auto_agreement_t qt
ON qt.policy_no = e.policy_no
LEFT JOIN datacenter.dc_yangg_qdcode qd
ON qd.code = e.selling_channel_type
LEFT JOIN datacenter.dc_tb_jc_c_tag cl
ON cl.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = e.policy_no
LEFT JOIN datacenter.dc_yangg_basecode_teams fg
ON fg.bm = z.department_name
AND fg.ks = y.section_office_name
--left join idst0.t_sell_policy_autobase_t zx on zx.policy_no=e.policy_no
--left join idst0.auto_agreement_extend_t et on et.policy_no = e.policy_no
LEFT JOIN idst0.auto_agreement_extend_t et
ON et.policy_no = e.policy_no
LEFT JOIN idst0.t_sell_policy_autobase_t zx
ON zx.policy_no = e.policy_no
LEFT JOIN datacenter.dc_YZH_ZXYS YS
ON YS.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> = nvl(zx.workerno,
et.telpartnercode)
--left join v_lsj_dimian dm on dm.vin=v.vin and e.selling_channel_type='25' and dm.MEMO like'%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%'
--left join datacenter.dc_lsj_zx_team zt on zt.name=coalesce(zc.name,zc1.name,bc.name,dm.JBRMC)
WHERE t.signature_date >= to_date('2023-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
AND t.signature_date < to_date(to_char(SYSDATE - 1,
'yyyy-mm-dd') || ' 23:59:59',
'yyyy-mm-dd hh24:mi:ss')
--and t.endorsement_no = '<EFBFBD><EFBFBD>'
AND e.policy_status = '1' --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
AND qt.tflag = '0' --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
AND qt.usage_xm = '<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>
--and e.policy_no in ('AXIMC90Y1419B038594J','AXIMC90CTP19B039593R','AXIMC04CTP19B013473X')
AND e.planned_end_date - e.inception_date >= 360
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
)
-----<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
,
dd2 AS
(SELECT ǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
the_year,
the_month,
bm,
bmdm,
<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>N,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>N,
CASE
WHEN pdh = '<EFBFBD><EFBFBD>' THEN
tid
END tid,
to_number('1') <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>,
COUNT(DISTINCT CASE
WHEN pdh = '<EFBFBD><EFBFBD>' THEN
bdh
END) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
SUM(bf) <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FROM (SELECT DISTINCT *
FROM aa) aa
GROUP BY bm,
bmdm,
CASE
WHEN pdh = '<EFBFBD><EFBFBD>' THEN
tid
END,
the_year,
the_month,
BTID,
<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>N,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>N
UNION
SELECT ǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
the_year,
the_month,
bm,
bmdm,
<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD>ϯ<EFBFBD>Ŷ<EFBFBD>,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>N,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>N,
CASE
WHEN btid = tid THEN
''
ELSE
btid
END btid,
to_number('0') <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>,
to_number('0') <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
to_number('0') <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FROM (SELECT DISTINCT *
FROM aa) aa),
DD AS
(SELECT *
FROM DD2
WHERE TID IS NOT NULL)
--select * from dd
,
bb AS
(SELECT DISTINCT q.policy_no bdh,
q.endorsement_no pdh,
qna.t_cre tid,
to_number(to_char(q.signature_date,
'yyyy')) || '<EFBFBD><EFBFBD>' nf,
(to_char(q.signature_date,
'mm')) mm_f,
to_char(q.signature_date,
'dd') || '<EFBFBD><EFBFBD>' dd,
q.signature_date sj,
round((pt.premium_amount - nvl(pt.taxamount,
0)) * c.rate / 100,
2) bf,
z.department_name bm
FROM idst0.nonauto_agreement_request_t q
LEFT JOIN idst0.nonauto_agreement_t e
ON e.policy_no = q.policy_no
LEFT JOIN idst0.nonauto_premium_t pt
ON pt.endorsement_no = q.endorsement_no
AND pt.policy_no = q.policy_no
LEFT JOIN idst0.reinsurance_t r
ON r.reinsurance_policy_no = e.policy_no
LEFT JOIN idst0.exrate_month_t c
ON pt.currency_code = c.bzh
AND to_char(q.signature_date,
'YYYY') = c.theyear
AND to_char(q.signature_date,
'fmmm') = c.themonth
LEFT JOIN idst0.rydm_t x
ON x.staff_code = e.operator_code
LEFT JOIN idst0.ks_t y
ON y.section_office_code = x.section_office_code
LEFT JOIN idst0.bm_t z
ON z.department_code = x.department_code
LEFT JOIN ywglxt.q_nonauto_agreement_t qna
ON qna.policy_no = q.policy_no
LEFT JOIN datacenter.dc_yangg_gkxzh gk
ON gk.product_code = e.product_code --<EFBFBD><EFBFBD>ɢ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--left join datacenter.dc_yangg_zbxzh zb on zb.product_code = e.product_code --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LEFT JOIN dd
ON dd.tid = qna.t_cre
WHERE qna.tflag = '0'
AND (CASE
WHEN q.endorsement_no != '<EFBFBD><EFBFBD>' AND
round((pt.premium_amount - nvl(pt.taxamount,
0)) * c.rate / 100,
2) != 0 THEN
'<EFBFBD><EFBFBD>'
END) IS NULL
--and q.endorsement_no = '<EFBFBD><EFBFBD>'
AND e.policy_status = '1'
AND gk.product_code IS NOT NULL
AND (e.product_code LIKE '2%' OR e.product_code LIKE '1106%' --<EFBFBD> --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OR e.product_code LIKE '1107%' OR e.product_code LIKE '1108%' OR e.product_code LIKE '1307%' OR e.product_code LIKE '1304A400%' --<EFBFBD>Ҳ<EFBFBD>
)
--and e.product_code not in ('22KC9800')
AND q.signature_date >= to_date('2023-01-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
AND q.signature_date < to_date(to_char(SYSDATE - 1,
'yyyy-mm-dd') || ' 23:59:59',
'yyyy-mm-dd hh24:mi:ss')
AND e.planned_end_date - e.inception_date >= 90
AND dd.tid IS NOT NULL
--<EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD>˿ͻ<EFBFBD>)
)
--SELECT * FROM BB
,
cc AS
(SELECT mm_f,
tid <EFBFBD>ں<EFBFBD>֤<EFBFBD><EFBFBD>,
COUNT(DISTINCT bdh) <EFBFBD>ںϱ<EFBFBD><EFBFBD><EFBFBD>,
SUM(bf) <EFBFBD>ںϱ<EFBFBD><EFBFBD><EFBFBD>
FROM bb
GROUP BY tid,
mm_f),
ff AS
(SELECT dd.*,
cc.*
FROM dd
LEFT JOIN cc
ON cc.<EFBFBD>ں<EFBFBD>֤<EFBFBD><EFBFBD> = dd.tid
AND cc.mm_f = dd.the_month) --OR cc.<EFBFBD>ں<EFBFBD>֤<EFBFBD><EFBFBD> = dd.btid
--select * from ff
SELECT to_date(ǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
'yyyy-mm-dd') ǩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
the_year <EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
the_month <EFBFBD>·<EFBFBD>,
bm <EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
bmdm <EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><E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><EFBFBD>N
ORDER BY <EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
SELECT *
FROM desktop_archievement_admin.<EFBFBD><EFBFBD>ϯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD>;