客户标签koucx20210126.sql 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. --更新客户标签信息
  2. CREATE OR REPLACE PROCEDURE shanglifeecif.updateIndividualLable() IS
  3. DECLARE
  4. BEGIN
  5. --label1: 无来源。Individual.Education
  6. --label2: Individual.Occupation,逻辑见上
  7. UPDATE shanglifeecif.Individual si1 SET si1.label2 = (SELECT si2.Occupation FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  8. --标签3 根据Individual.Birthday年代,更新为70后,80后等
  9. UPDATE shanglifeecif.Individual si1 SET si1.label3 = (SELECT substr(si2.birthday,3,1) || '0后' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  10. --Label4:根据Individual.Birthday算出年龄,儿童:[0,13),少年:[13,19),青年:[19,41),中年:[41,66),老年:[66,)
  11. UPDATE shanglifeecif.Individual si1 SET si1.label4 = (SELECT CASE WHEN temp.age>=0 AND temp.age<13 THEN '儿童' WHEN temp.age>=13 AND temp.age <19 THEN '少年' WHEN temp.age >=19 AND temp.age <41 THEN '青年' WHEN temp.age >=41 AND temp.age <66 THEN '中年' ELSE '老年' END FROM (SELECT TRUNC(months_between(sysdate, si2.birthday)/12) age,si2.indid FROM shanglifeecif.Individual si2) temp WHERE temp.indid = si1.indid);
  12. --Label5: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  13. --Label6: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  14. --Label7:保留暂不实现
  15. --Label8:保留暂不实现
  16. --标签9 已婚,未婚 无来源。Individual.MaritalStat,查询个体关系表(IndRelationShip),RSType = '配偶',如果有记录则更新为已婚,否则更新为null
  17. UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT CASE WHEN temp.cnum >0 THEN '已婚' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '配偶' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  18. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT CASE WHEN cnum >0 THEN '已婚' END FROM (SELECT nvl(count(*),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE si1.indid = sirs.indid2 AND sirs.rstype = '配偶' GROUP BY sirs.indid2) temp WHERE si1.indid = temp.indid2)
  19. --Label10:查询IndRelationShip,RSType='父母',首先将返回记录数更新Individual.COChild,若记录数为0,则更新本字段为'无子女',若记录数为1,则更新本字段为'1孩',若记录数大于等于2,则更新本字段为'2孩及以上'
  20. UPDATE shanglifeecif.Individual si1 SET si1.COChild = (SELECT CASE WHEN temp.cnum == 0 THEN '无子女' WHEN temp.cnum == 1 THEN '1孩' ELSE '2孩及以上' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '父母' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  21. UPDATE shanglifeecif.Individual si1 SET si1.label10 = (SELECT CASE WHEN temp.cnum == 0 THEN '无子女' WHEN temp.cnum == 1 THEN '1孩' ELSE '2孩及以上' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '父母' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  22. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT '已婚' FROM shanglifeecif.IndRelationShip sirs WHERE si1.indid = sirs.indid2 AND sirs.rstype = '配偶')
  23. --Label11:todo:无来源,逻辑需要说明清楚
  24. --Label12:todo:无来源,逻辑需要说明清楚。Individual.Drinking
  25. UPDATE shanglifeecif.Individual si1 SET si1.label12 = (SELECT si2.Drinking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  26. --Label13:todo:无来源,逻辑需要说明清楚。Individual.Smoking
  27. UPDATE shanglifeecif.Individual si1 SET si1.label13 = (SELECT si2.Smoking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  28. --Label14:todo:无来源,逻辑需要说明清楚。Individual.Cdiseases
  29. --Label15:todo:无来源,逻辑需要说明清楚。
  30. --Label16:todo:无来源,逻辑需要说明清楚。Individual.FMHistory
  31. --Label17:todo:无来源,逻辑需要说明清楚。Individual.Pregnancy
  32. --Label18:todo:无来源,逻辑需要说明清楚。
  33. --Label19:保留暂不实现
  34. --Label20:todo:无来源,逻辑需要说明清楚。
  35. --Label21:todo:无来源,Individual.PIncome:[0,120000],'低收入';(120000,1000000],'中产';(1000000,),'富人'
  36. UPDATE shanglifeecif.Individual si1 SET si1.Label21 = (SELECT CASE WHEN si2.pincome >=0 AND si2.pincome<=120000 THEN '低收入' WHEN si2.pincome >120000 AND si2.pincome<=1000000 THEN '中产' WHEN si2.pincome > 1000000 THEN '富人' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  37. --Label22:todo:无来源,Individual.COVehicle:0,'无车';1,'1辆车';(1,),'2辆车以上'
  38. UPDATE shanglifeecif.Individual si1 SET si1.Label22 = (SELECT CASE WHEN si2.COVehicle ==0 THEN '无车' WHEN si2.COVehicle == 1 THEN '1辆车' WHEN si2.COVehicle > 1 THEN '2辆车以上' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  39. --Label23:todo:无来源,Individual.CORP:0,'无房';1,'1套房';(1,),'2套房以上'
  40. UPDATE shanglifeecif.Individual si1 SET si1.Label23 = (SELECT CASE WHEN si2.CORP ==0 THEN '无房' WHEN si2.CORP == 1 THEN '1套房' WHEN si2.CORP > 1 THEN '2套房以上' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  41. --Label24:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG = '有效',若无记录则更新Individual.NOVPolicy为0,否则更新NOVPolicy为记录数。若NOVPolicy>0,则更新Individual.Label24为'持有寿险有效保单',否则更新为'未持有寿险有效保单'
  42. --第一步 更新Individual.NOVPolicy有效记录数
  43. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = (SELECT temp.cuscount FROM (SELECT nvl(count(spi.customerno),0) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno WHERE spi.appflag = '有效' GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  44. --第二步 更新 Individual.NOIVPolicy 无效记录数
  45. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = (SELECT temp.cuscount FROM (SELECT nvl(count(spi.customerno),0) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno WHERE spi.appflag <> '有效' GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  46. --最后一步 更新标签 24
  47. UPDATE shanglifeecif.Individual si1 SET si1.label24 = (SELECT CASE WHEN nvl(si2.novpolicy,0)>0 THEN '持有寿险有效保单' ELSE '未持有寿险有效保单' END FROM shanglifeecif.individual si2 WHERE si2.indid = si1.indid);
  48. --Label25:将Individual.NOVPolicy+Individual.NOIVPolicy的值更新ndividual.Label25
  49. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (SELECT (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  50. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (SELECT CASE
  51. WHEN si2.label25 == 0 THEN '无保单'
  52. WHEN si2.label25 == 1 THEN '1件'
  53. WHEN si2.label25 == 2 THEN '2件'
  54. WHEN si2.label25 >= 3 AND si2.label25 <= 5 THEN '3-5件'
  55. WHEN si2.label25 >= 6 AND si2.label25 <= 10 THEN '6-10件'
  56. WHEN si2.label25 >= 11 AND si2.label25 <= 20 THEN '11-20件'
  57. WHEN si2.label25 >= 21 AND si2.label25 <= 50 THEN '21-50件'
  58. WHEN si2.label25 > 50 THEN '50件以上'
  59. END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  60. --Label26:InsuranceArrangement.PolicyNo = AUDIT_LN_LIST.CONTNO,以AUDIT_LN_LIST.LNMONEY更新InsuranceArrangement.LoanMoney,以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),若无记录更新Individual.Label26为Null,若LoanMoney>0则更新Individual.Label26为'有贷款',否则更新为'无贷款'
  61. --第一步 以AUDIT_LN_LIST.LNMONEY更新InsuranceArrangement.LoanMoney
  62. UPDATE shanglifeecif.insurancearrangement sig SET sig.LoanMoney =(SELECT temp.lnmoney FROM (SELECT sall.contno,sum(sall.lnmoney) lnmoney FROM shanghailifeecif.audit_ln_list sall GROUP BY sall.contno) temp WHERE temp.contno = sig.policyno);
  63. --第二步 以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID)
  64. --SELECT sig.applicantid,sum(sig.loanmoney) loanmoney FROM shanglifeecif.insurancearrangement sig GROUP BY sig.applicantid
  65. UPDATE shanglifeecif.Individual si1 SET si1.Label26 =(SELECT CASE WHEN temp.loanmoney > 0 THEN '有贷款' WHEN temp.loanmoney = 0 THEN '无贷款' ELSE NULL END FROM (SELECT sig.applicantid,sum(sig.loanmoney) loanmoney FROM shanglifeecif.insurancearrangement sig GROUP BY sig.applicantid) temp WHERE si1.indid = temp.applicantid);
  66. --Label27:todo:无来源,逻辑需要说明清楚。
  67. --Label28:保留暂不实现
  68. --Label29:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表(CUSTOMERNO),POLICY_INFORMATION.APPFLAG='有效' and POLICY_INFORMATION.PAYINTV='趸缴',若有记录则更新Individual.NOSPInsurance和本标签为'有趸交保单'
  69. UPDATE shanglifeecif.Individual si1 SET si1.label29 =
  70. (SELECT CASE WHEN temp.cnum>0 THEN '有趸交保单' END FROM (SELECT count(1) cnum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.APPFLAG = '有效' AND spi.PAYINTV = '趸缴' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  71. UPDATE shanglifeecif.Individual si1 SET si1.NOSPInsurance =
  72. (SELECT CASE WHEN temp.cnum>0 THEN '有趸交保单' END FROM (SELECT count(1) cnum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.APPFLAG = '有效' AND spi.PAYINTV = '趸缴' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  73. --Label30:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.ISelf为NULL,若有记录且RELATIONTOAPPNT仅为'本人'则若无记录则更新Individual.ISelf为'仅本人投保',若有记录且RELATIONTOAPPNT不为'本人'则若无记录则更新Individual.ISelf为'本人未投保',否则更新Individual.ISelf为'本人已投保'
  74. UPDATE shanglifeecif.Individual si1 SET si1.iself = (SELECT CASE WHEN temp.snum>0 THEN '本人已投保' WHEN temp.snum=0 THEN '本人未投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  75. UPDATE shanglifeecif.Individual si1 SET si1.iself = (SELECT CASE WHEN temp.snum=0 AND si1.iself ='本人已投保' THEN '仅本人投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  76. --label31 以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Iparent为NULL,若有记录且RELATIONTOAPPNT仅为'父母'则若无记录则更新Individual.Iparent为'仅父母投保',若有记录且RELATIONTOAPPNT不为'父母'则若无记录则更新Individual.Iparent为'父母未投保',否则更新Individual.Iparent为'父母已投保'
  77. UPDATE shanglifeecif.Individual si1 SET si1.Iparent = (SELECT CASE WHEN temp.snum > 0 THEN '父母已投保' WHEN temp.snum=0 THEN '父母未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  78. UPDATE shanglifeecif.Individual si1 SET si1.Iparent = (SELECT CASE WHEN temp.snum=0 AND si1.Iparent = '父母已投保' THEN '仅父母投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  79. --Label32:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.IChildren为NULL,若有记录且RELATIONTOAPPNT仅为'子女'则若无记录则更新Individual.IChildren为'仅子女投保',若有记录且RELATIONTOAPPNT不为'子女'则若无记录则更新Individual.IChildren为'子女未投保',否则更新Individual.IChildren为'子女已投保'
  80. UPDATE shanglifeecif.Individual si1 SET si1.IChildren = (SELECT CASE WHEN temp.snum>0 THEN '子女已投保' WHEN temp.snum=0 THEN '子女未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  81. UPDATE shanglifeecif.Individual si1 SET si1.IChildren = (SELECT CASE WHEN temp.snum=0 AND si1.IChildren = '子女已投保' THEN '仅子女投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  82. --Label33:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Imate为NULL,若有记录且RELATIONTOAPPNT仅为'配偶'则若无记录则更新Individual.Imate为'仅配偶投保',若有记录且RELATIONTOAPPNT不为'配偶'则若无记录则更新Individual.Imate为'配偶未投保',否则更新Individual.Imate为'配偶已投保'
  83. UPDATE shanglifeecif.Individual si1 SET si1.Imate = (SELECT CASE WHEN temp.snum>0 THEN '配偶已投保' WHEN temp.snum=0 THEN '配偶未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  84. UPDATE shanglifeecif.Individual si1 SET si1.Imate = (SELECT CASE WHEN temp.snum=0 AND si1.Imate = '配偶已投保' THEN '仅配偶投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid)
  85. --Label34:保留暂不实现
  86. --Label35:保留暂不实现
  87. --Label36:保留暂不实现
  88. --Label37:保留暂不实现
  89. --Label38:保留暂不实现
  90. --Label39:保留暂不实现
  91. --Label40:保留暂不实现
  92. --Label41:保留暂不实现
  93. --Label42:保留暂不实现
  94. --Label43:todo:逻辑需要说明清楚(到上游源表和字段)。
  95. --Label44:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG<>'有效',若无记录则更新Individual.NOIVPolicy为0,否则更新NOIVPolicy为记录数。若NOIVPolicy>0,则更新Individual.Label44为'有失效保单',否则更新为'无失效保单'
  96. UPDATE shanglifeecif.Individual si1 SET si1.label44 = (SELECT CASE WHEN si2.noivpolicy>0 THEN '有失效保单' END FROM shanglifeecif.individual si2 WHERE si2.indid = si1.indid);
  97. --LABEL45:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且riskperiod='长期险',若无记录则更新Individual.Label45为NULL,若有记录且paycount= payendyear则更新Individual.Label45为'有缴费期满长险保单',否则更新Individual.Label45为'无缴费期满长险保单'
  98. UPDATE shanglifeecif.Individual si1 SET si1.label45 = (SELECT CASE WHEN temp.cuscount IS NULL THEN NULL WHEN temp.cuscount>0 THEN '有缴费期满长险保单' ELSE '无缴费期满长险保单' END FROM (SELECT count(spi.customerno) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno WHERE spi.riskperiod='长期险' AND spi.paycount = spi.payendyear GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  99. --Label46:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label46为NULL,若有记录且paycount= payendyear则更新Individual.Label46为'有续期缴费的保单',否则更新Individual.Label46为'无有续期缴费的保单'
  100. UPDATE shanglifeecif.Individual si1 SET si1.label46 = (SELECT CASE WHEN temp.cuscount IS NULL THEN NULL WHEN temp.cuscount>0 THEN '有续期缴费的保单' ELSE '无有续期缴费的保单' END FROM (SELECT count(spi.customerno) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno WHERE spi.paycount = spi.payendyear GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  101. --Label47:todo:逻辑需要说明清楚(到上游源表和字段)。
  102. --Label48:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最早日期(PADate)更新Individual.FADate
  103. UPDATE shanglifeecif.Individual si1 SET si1.FADate =
  104. (SELECT '首次投保日期' || temp.padate FROM (SELECT min(si.PADate) padate,si.applicantid FROM shanglifeecif.insurancearrangement si GROUP BY si.applicantid) temp WHERE temp.applicantid = si1.indid);
  105. --Label49:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最近日期(PADate)更新Individual.LAPPDate,最后用当前日期减去Individual.LAPPDate更新Label49
  106. UPDATE shanglifeecif.Individual si1 SET si1.LAPPDate = (SELECT temp.PADate FROM (SELECT min(si.PADate) padate,si.applicantid FROM shanglifeecif.insurancearrangement si GROUP BY si.applicantid) temp WHERE temp.applicantid = si1.indid);
  107. UPDATE shanglifeecif.Individual si1 SET si1.Label49 = (SELECT '最后一次投保距今' || TRUNC(months_between(sysdate(), si2.LAPPDate)/12) || '天' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  108. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel
  109. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel,并更新此标签为:'最近保单'+Individual.LPChannel
  110. UPDATE shanglifeecif.Individual si1 SET si1.LPChannel = (SELECT temp.agentchannel FROM (SELECT si.agentchannel,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate DESC) rd FROM shanglifeecif.InsuranceArrangement si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  111. UPDATE shanglifeecif.Individual si1 SET si1.Label50 = (SELECT '最近保单' || si1.LPChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  112. --Label51:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentOrg更新Individual.LPOrg,并更新此标签为:'最近'+Individual.LPOrg+'机构'
  113. UPDATE shanglifeecif.Individual si1 SET si1.LPOrg = (SELECT temp.AgentOrg FROM (SELECT si.AgentOrg,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate DESC) rd FROM shanglifeecif.InsuranceArrangement si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  114. UPDATE shanglifeecif.Individual si1 SET si1.Label51 = (SELECT '最近' || si2.LPOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid) ;
  115. --Label52:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentChannel更新Individual.FAChannel
  116. UPDATE shanglifeecif.Individual si1 SET si1.FAChannel = (SELECT tt.agentchannel FROM (SELECT si.agentchannel,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si ) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  117. UPDATE shanglifeecif.Individual si1 SET si1.Label52 = (SELECT '首单' || si2.FAChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  118. --Label53:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentOrg更新Individual.FAOrg
  119. UPDATE shanglifeecif.Individual si1 SET si1.FAOrg = (SELECT tt.AgentOrg FROM (SELECT si.AgentOrg,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  120. UPDATE shanglifeecif.Individual si1 SET si1.Label53 = (SELECT '首单' || si2.FAOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  121. --Label54:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的PolicyState更新Individual.LPState
  122. UPDATE shanglifeecif.Individual si1 SET si1.LPState = (SELECT tt.PolicyState FROM (SELECT si.PolicyState,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  123. --Label55 :Label55:由于上游保全类型信息分散在AUDIT_EDORLIST.EDORNAME和edorinfo.edortype 中,同时edorinfo.edortype为code需要转为string(具体映射见下)。以上游客户号(Individual.SCustID)分别查询AUDIT_EDORLIST表和edorinfo表,取保全生效日期最近的记录的更新的保全类型更新Individual.LPOSType。todo:edorinfo.edortype为code,需要转为string,edorinfo中需要增加上游客户号,否则需要多一次关联,建议大数据平台处理完成。
  124. --AUDIT_EDORLIST表里没有上游客户号,UPDATE shanglifeecif.Individual si1 SET si1.LPOSType =(SELECT ae.edorname FROM shanghailifeecif.audit_edorlist ae )
  125. UPDATE shanglifeecif.Individual si1 SET si1.lpostype = (SELECT tt.edortype FROM ( SELECT temp.scustid,temp.edortype,temp.edorvalidate,row_number()OVER(PARTITION BY temp.scustid ORDER BY temp.edorvalidate DESC) rd FROM ((SELECT si2.scustid,sae.edorname edortype,sae.edorvalidate FROM shanglifeecif.Individual si2
  126. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  127. LEFT JOIN shanghailifeecif.audit_edorlist sae ON sae.contno = spi.contno)
  128. UNION
  129. ( SELECT si2.scustid,se.edortype,se.edorappdate edorvalidate FROM shanglifeecif.Individual si2
  130. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  131. LEFT JOIN shanghailifeecif.edorinfo se ON se.contno = spi.contno)) temp) tt WHERE tt.scustid = si1.scustid AND tt.rd = 1);
  132. --Label56:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询INSURANCEINFO表 and INSURANCEINFO.APPFLAG = '已退保',若有记录则更新此标签为'有退保保单'
  133. UPDATE shanglifeecif.Individual si1 SET si1.Label56 =
  134. (SELECT CASE WHEN temp.cunm > 0 THEN '有退保保单' END FROM
  135. (
  136. SELECT count(1) cunm,si2.scustid FROM shanglifeecif.Individual si2
  137. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  138. LEFT JOIN shanghailifeecif.INSURANCEINFO sio ON spi.CONTNO = sio.CONTNO
  139. WHERE sio.APPFLAG = '已退保' GROUP BY si2.scustid
  140. ) temp WHERE temp.scustid = si1.scustid);
  141. --Label57:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询AUDIT_CLAIM_INSURANCE表,取AUDIT_CLAIM_INSURANCE.RGTDATE最近对应的AUDIT_CLAIM_INSURANCE.RISKTYPE更新此标签。todo:实际数据仅有寿险、意外险、健康险,取值是否正确?
  142. UPDATE shanglifeecif.Individual si1 SET si1.Label57 =
  143. (SELECT temp.RISKTYPE FROM (
  144. SELECT si2.scustid,saci.RISKTYPE,row_number()OVER(PARTITION BY si2.scustid ORDER BY saci.RGTDATE DESC) rd FROM shanglifeecif.Individual si2
  145. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  146. LEFT JOIN shanghailifeecif.audit_claim_insurance saci ON saci.CONTNO = spi.CONTNO
  147. ) temp WHERE si1.scustid = temp.scustid AND temp.rd = 1);
  148. --Label59 :以个体ID(Individual.IndID)查询InsuranceClaimThread表(Individual.IndID=InsuranceClaimThread.ApplicantID), 以最近日期(CNDate)的ClaimCaseStatus更新Individual.CNStatus
  149. UPDATE shanglifeecif.Individual si1 SET si1.CNStatus =(SELECT temp.ClaimCaseStatus FROM (SELECT si.ClaimCaseStatus,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.CNDate DESC) rd FROM shanglifeecif.insuranceclaimthread si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  150. --Label60:保留暂不实现
  151. --Label61:todo:逻辑需要说明清楚(到上游源表和字段)。
  152. --Label62:保留暂不实现
  153. --Label63:todo:逻辑需要说明清楚(到上游源表和字段)。
  154. --Label64:todo:逻辑需要说明清楚(到上游源表和字段)。
  155. --Label65:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label65为NULL,若仅一条记录则更新Individual.Label65为'一单寿险客户'
  156. UPDATE shanglifeecif.Individual si1 SET si1.Label65 =
  157. (SELECT CASE WHEN tt.cnum = 1 THEN '一单寿险客户' END FROM (SELECT nvl(count(spi.customerno),0) cnum,max(si2.indid) indid FROM shanghailifeecif.policy_information spi LEFT JOIN shanglifeecif.Individual si2 ON si2.scustid = spi.customerno GROUP BY spi.customerno) tt WHERE si1.indid = tt.indid);
  158. --Label66:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label66为NULL,若 paycount= payendyear更新Individual.Label66为'缴费期满客户',否则更新为'非缴费期满客户
  159. UPDATE shanglifeecif.Individual si1 SET si1.Label66 =
  160. (SELECT CASE WHEN tt.cnum >0 THEN '缴费期满客户' END FROM (SELECT nvl(count(spi.customerno),0) cnum,max(si2.indid) indid FROM shanghailifeecif.policy_information spi LEFT JOIN shanglifeecif.Individual si2 ON si2.scustid = spi.customerno and spi.paycount= spi.payendyear GROUP BY spi.customerno) tt WHERE si1.indid = tt.indid);
  161. --Label67:若Individual.Birthday的月日与上海人寿司庆日月日相同,则设置此标签为:'生日与司庆日同天'。todo:需要确定司庆日是几月几号
  162. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = (SELECT CASE WHEN substr(si2.birthday,6,10) = '02-15' THEN '生日与司庆日同天' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  163. --Label68:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表, and POLICY_INFORMATION.APPFLAG='有效',若有记录则设置此标签为'持有有效保单',否则则设置为'未持有有效保单'
  164. UPDATE shanglifeecif.Individual si1 SET si1.Label68 = (SELECT CASE WHEN si2.NOVPolicy>0 THEN '持有有效保单' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  165. --Label69:Individual.CustClass,逻辑见上(一.7)
  166. UPDATE shanglifeecif.Individual si1 SET si1.Label69 = (SELECT si2.CustClass FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  167. --Label70:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Scenario更新此标签
  168. UPDATE shanglifeecif.Individual si1 SET si1.Label70 = (SELECT temp.Scenario FROM (SELECT sp.Scenario,sp.PartyID,row_number()OVER(PARTITION BY sp.PartyID ORDER BY sp.SDate DESC) rd FROM shanglifeecif.PartyTimeLine sp) temp WHERE si1.indid = temp.PartyID AND temp.rd = 1);
  169. --Label71:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Channel更新此标签
  170. UPDATE shanglifeecif.Individual si1 SET si1.Label71 = (SELECT temp.Channel FROM (SELECT sp.Channel,sp.PartyID,row_number()OVER(PARTITION BY sp.PartyID ORDER BY sp.SDate DESC) rd FROM shanglifeecif.PartyTimeLine sp) temp WHERE si1.indid = temp.PartyID AND temp.rd = 1);
  171. --Label72:保留暂不实现
  172. --Label73
  173. --Label74
  174. --Label75
  175. --Label76
  176. --Label77:Individual.Birthday 距离当前日期5天内,更新Individual.Label77为'本人生日临近',否则为NULL
  177. UPDATE shanglifeecif.Individual si1 SET si1.Label77 = (SELECT CASE WHEN DATEDIFF(sysdate(), si2.birthday)<=5 THEN '本人生日临近' END FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  178. --Label78:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'父亲'或'母亲'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label78为'父母生日临近',否则为NULL
  179. UPDATE shanglifeecif.Individual si1 SET si1.Label78 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '父母生日临近' END FROM (
  180. SELECT sis.indid2 FROM shanglifeecif.Individual si2 LEFT JOIN shanglifeecif.IndRelationShip sis ON si2.indid = sis.indid1 WHERE (sis.role2 = '父亲' or sis.role2 = '母亲') GROUP BY sis.indid2) tt WHERE si1.indid = tt.indid2);
  181. --Label79:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'儿子'或'女儿'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label79为'子女生日临近',否则为NULL
  182. UPDATE shanglifeecif.Individual si1 SET si1.Label79 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '子女生日临近' END FROM (
  183. SELECT sis.indid2 FROM shanglifeecif.Individual si2 LEFT JOIN shanglifeecif.IndRelationShip sis ON si2.indid = sis.indid1 WHERE (sis.role2 = '儿子' or sis.role2 = '女儿') GROUP BY sis.indid2) tt WHERE si1.indid = tt.indid2);
  184. --Label96:根据Individual.Birthday算出当前年龄,如果50<=年龄<60,则更新Individual.Label96为'大龄',否则为NULL
  185. UPDATE shanglifeecif.Individual si1 SET si1.Label96 = (SELECT CASE WHEN TRUNC(months_between(sysdate, si2.birthday)/12)>=50 AND TRUNC(months_between(sysdate, si2.birthday)/12)<60 THEN '大龄' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  186. --Label97:根据Individual.Birthday算出当前年龄,如果60<=年龄,则更新Individual.Label97为'高龄',否则为NULL
  187. UPDATE shanglifeecif.Individual si1 SET si1.Label97 = (SELECT CASE WHEN TRUNC(months_between(sysdate, si2.birthday)/12)>=60 THEN '高龄' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  188. --Label98:根据Individual.Occupation,若为记者、律师、公务员、媒体、金融行业,则更新Individual.Label98为'敏感职业',否则为NULL
  189. UPDATE shanglifeecif.Individual si1 SET si1.Label98 = (SELECT CASE WHEN si2.occupation = '记者' OR si2.occupation = '律师' OR si2.occupation = '公务员' OR si2.occupation = '媒体' OR si2.occupation = '金融行业' THEN '敏感职业' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  190. --Label109:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='报案'且 InsuranceClaimThread.CNDate距当前日期超过7天,则更新Individual.Label109为'理赔报案追踪'
  191. UPDATE shanglifeecif.Individual si1 SET si1.Label109 = (SELECT CASE WHEN count(1)>0 THEN '理赔报案追踪' END FROM shanglifeecif.insuranceclaimthread sit WHERE si1.indid = sit.applicantid AND sit.claimstatus = '报案' AND DATEDIFF(sysdate(), sit.CNDate)>7);
  192. --Label110:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='受理' or '立案',则更新Individual.Label110为'理赔处理中'
  193. UPDATE shanglifeecif.Individual si1 SET si1.Label110 = (SELECT CASE WHEN count(1)>0 THEN '理赔处理中' END FROM shanglifeecif.insuranceclaimthread sit WHERE si1.indid = sit.applicantid AND (sit.claimstatus = '受理' OR sit.claimstatus = '立案'));
  194. --Label112:先以个体ID(Individual.IndID)得到InsuranceArrangement.PolicyNo,再以此关联AUDIT_EDORLIST,若有记录且保全状态EDORSTATE<>'确认生效' and '复核终止' and '强制终止',则更新Individual.Label111为'保全处理中'
  195. UPDATE shanglifeecif.Individual si1 SET si1.Label112 = (SELECT CASE WHEN nvl(count(sae.contno),0) > 0 THEN '保全处理中' END FROM (SELECT si1.indid indid,max(sia.policyno) policyno FROM shanglifeecif.Individual si1 LEFT JOIN shanglifeecif.InsuranceArrangement sia ON si1.indid = sia.applicantid GROUP BY si1.indid) tt LEFT JOIN shanghailifeecif.audit_edorlist sae ON sae.contno = tt.policyno AND sae.edorstate <> '确认生效' AND sae.edorstate <> '复核终止' AND sae.edorstate <> '强制终止' WHERE si1.indid = tt.indid);
  196. UPDATE shanglifeecif.Individual si1 SET si1.Label70 =
  197. (SELECT temp.scenario FROM (
  198. SELECT qi.applicantid,qp.threadid,qp.scenario,row_number()OVER(PARTITION BY qp.threadid ORDER BY qp.created_time DESC) rd FROM qxp.partytimeline qp
  199. LEFT JOIN qxp.insurancearrangement qi ON qp.threadid = qi.policyno
  200. WHERE rd = 1
  201. ) temp WHERE temp.applicantid = si1.indid)
  202. --注册官微
  203. UPDATE shanglifeecif.Individual si1 SET si1.Label74 = (SELECT CASE WHEN COUNT(1)>0 THEN '注册官微' END FROM shanghailifeecif.wx_list wl WHERE wl.certificate_no = si1.idcard)
  204. --长通话逻辑contnos为客户的保单号select (select lo.call_length from ucc_rms_recorderlog lo where lo.call_id=m.call_id) as lenth from cc_record_main mwhere m.contnos='2019082000110188'
  205. UPDATE shanglifeecif.Individual si1 SET si1.label10 =
  206. (SELECT CASE WHEN tt.avgCallLenth>600 THEN '长通话' END FROM (
  207. SELECT temp.contnos,(temp.lenth/temp.callNum) as avgCallLenth,qi.applicantid FROM(
  208. select (select lo.call_length from shanghailifeecif.ucc_rms_recorderlog lo where lo.call_id=m.call_id) as lenth,count(1) AS callNum,m.contnos from shanghailifeecif.cc_record_main m
  209. GROUP BY m.contnos
  210. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.contnos = qi.policyno) tt WHERE tt.applicantid = si1.indid)
  211. --要求较多,每次来电均下转办单
  212. UPDATE shanglifeecif.Individual si1 SET si1.label103 =
  213. -- (SELECT '要求多' FROM shanghailifeecif.cc_swfflowmain swf
  214. -- LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  215. -- WHERE swf.flowid LIKE '%ZX%' AND si1.indid = qi.applicantid)
  216. (
  217. SELECT CASE WHEN t.callNum==t.swf_num THEN '要求较多' END FROM (
  218. SELECT count(*) AS callNum,srm.contnos,(SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  219. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  220. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  221. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  222. WHERE si1.indid = qi.applicantid
  223. )
  224. UPDATE shanglifeecif.Individual si1 SET si1.label104 =
  225. --(SELECT '易投诉升级' FROM shanghailifeecif.cc_swfflowmain swf
  226. --LEFT JOIN shanghailifeecif.cc_swf_sort scc ON scc.complaintProject = swf.id
  227. --LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  228. -- WHERE swf.flowid LIKE '%ZX%' AND scc.idname='投诉' AND si1.indid = qi.applicantid)
  229. (
  230. SELECT CASE WHEN t.callNum==t.swf_num THEN '易投诉升级' END FROM (
  231. SELECT count(*) AS callNum,srm.contnos,
  232. (SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  233. LEFT JOIN shanghailifeecif.cc_swf_sort scs ON swf.complaintproject = scs.id
  234. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  235. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  236. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  237. WHERE si1.indid = qi.applicantid
  238. )
  239. UPDATE shanglifeecif.Individual si1 SET si1.label105 =
  240. (SELECT '高频投诉' FROM (
  241. select count(1) as comnum,c.productno,DATEDIFF(max(c.inserttime),min(c.inserttime)) dayNum from shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  242. ) temp
  243. LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = temp.productno
  244. WHERE temp.comnum >= 2 AND temp.dayNum <180 AND si1.indid = qi.applicantid
  245. )
  246. SELECT c.productno,c.inserttime FROM shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  247. UPDATE shanglifeecif.Individual si1 SET si1.label106 =
  248. /*(SELECT CASE temp.complaintsSource when '914' then '重大投诉'
  249. when '919' then '重大投诉'
  250. when '915' then '重大投诉' END,qi.applicantid FROM (
  251. select c.complaintsSource,cd.productno from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd
  252. where cd.complaintsid=c.complaintsid
  253. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.productno = qi.policyno WHERE qi.applicantid = si1.indid)
  254. */
  255. (SELECT CASE WHEN tt.complaintsSource LIKE '%914%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%915%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%919%' THEN '重大投诉' END FROM (
  256. select group_concat(c.complaintsSource,',') AS complaintsSource,qi.applicantid from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd,qxp.insurancearrangement qi
  257. where cd.complaintsid=c.complaintsid AND qi.policyno = cd.productno
  258. GROUP BY qi.applicantid
  259. ) tt WHERE tt.applicantid = si1.indid)
  260. --lable_27 志广说只用判断有极短意外险不用判断仅有
  261. UPDATE shanglifeecif.Individual si1 SET si1.Label26 = (
  262. SELECT
  263. CASE
  264. WHEN temp.cnt >0 THEN
  265. '有极短意外险'
  266. END
  267. FROM
  268. (
  269. SELECT
  270. count(1) cnt,
  271. policy.customerno
  272. FROM
  273. shanghailifeecif.policy_information policy
  274. where
  275. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  276. and
  277. policy.riskperiod='短期险'
  278. and
  279. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  280. GROUP BY
  281. policy.customerno
  282. ) temp
  283. WHERE
  284. temp.customerno = si1.scustid
  285. );
  286. --2233条记录
  287. --lable_43
  288. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  289. SELECT
  290. CASE
  291. WHEN temp.cnt >0 THEN
  292. '有1年期短险保单'
  293. END
  294. FROM
  295. (
  296. SELECT
  297. count(1) cnt,
  298. policy.customerno
  299. FROM
  300. shanghailifeecif.policy_information policy
  301. where
  302. policy.SECURITY in('1年','6月','180天')
  303. and
  304. policy.riskperiod='短期险'
  305. and
  306. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  307. GROUP BY
  308. policy.customerno
  309. ) temp
  310. WHERE
  311. temp.customerno = si1.scustid
  312. );
  313. --529354条记录
  314. --lable_67 司庆日
  315. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = '司庆日' where birthday like '%-02-05';
  316. --3615
  317. EXCEPTION
  318. WHEN HIVE_EXCEPTION THEN
  319. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  320. WHEN Others THEN
  321. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  322. END ;
  323. --更新客户标签信息
  324. CREATE OR REPLACE PROCEDURE shanglifeecif.updateIndividualLable() IS
  325. DECLARE
  326. BEGIN
  327. --label1: 无来源。Individual.Education
  328. --label2: Individual.Occupation,逻辑见上
  329. UPDATE shanglifeecif.Individual si1 SET si1.label2 = (SELECT si2.Occupation FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  330. --标签3 根据Individual.Birthday年代,更新为70后,80后等
  331. UPDATE shanglifeecif.Individual si1 SET si1.label3 = (SELECT substr(si2.birthday,3,1) || '0后' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  332. --Label4:根据Individual.Birthday算出年龄,儿童:[0,13),少年:[13,19),青年:[19,41),中年:[41,66),老年:[66,)
  333. UPDATE shanglifeecif.Individual si1 SET si1.label4 = (SELECT CASE WHEN temp.age>=0 AND temp.age<13 THEN '儿童' WHEN temp.age>=13 AND temp.age <19 THEN '少年' WHEN temp.age >=19 AND temp.age <41 THEN '青年' WHEN temp.age >=41 AND temp.age <66 THEN '中年' ELSE '老年' END FROM (SELECT TRUNC(months_between(sysdate, si2.birthday)/12) age,si2.indid FROM shanglifeecif.Individual si2) temp WHERE temp.indid = si1.indid);
  334. --Label5: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  335. --Label6: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  336. --Label7:保留暂不实现
  337. --Label8:保留暂不实现
  338. --标签9 已婚,未婚 无来源。Individual.MaritalStat,查询个体关系表(IndRelationShip),RSType = '配偶',如果有记录则更新为已婚,否则更新为null
  339. UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT CASE WHEN temp.cnum >0 THEN '已婚' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '配偶' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  340. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT CASE WHEN cnum >0 THEN '已婚' END FROM (SELECT nvl(count(*),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE si1.indid = sirs.indid2 AND sirs.rstype = '配偶' GROUP BY sirs.indid2) temp WHERE si1.indid = temp.indid2)
  341. --Label10:查询IndRelationShip,RSType='父母',首先将返回记录数更新Individual.COChild,若记录数为0,则更新本字段为'无子女',若记录数为1,则更新本字段为'1孩',若记录数大于等于2,则更新本字段为'2孩及以上'
  342. --UPDATE shanglifeecif.Individual si1 SET si1.COChild = (SELECT CASE WHEN temp.cnum == 0 THEN '无子女' WHEN temp.cnum == 1 THEN '1孩' ELSE '2孩及以上' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '父母' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  343. UPDATE shanglifeecif.Individual si1 SET si1.label10 = (SELECT CASE WHEN temp.cnum == 0 THEN '无子女' WHEN temp.cnum == 1 THEN '1孩' ELSE '2孩及以上' END FROM (SELECT nvl(count(1),0) cnum,sirs.indid1 FROM shanglifeecif.IndRelationShip sirs WHERE sirs.rstype = '父母' GROUP BY sirs.indid1) temp WHERE si1.indid = temp.indid1);
  344. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT '已婚' FROM shanglifeecif.IndRelationShip sirs WHERE si1.indid = sirs.indid2 AND sirs.rstype = '配偶')
  345. --Label11:todo:无来源,逻辑需要说明清楚
  346. --Label12:todo:无来源,逻辑需要说明清楚。Individual.Drinking
  347. --UPDATE shanglifeecif.Individual si1 SET si1.label12 = (SELECT si2.Drinking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  348. --Label13:todo:无来源,逻辑需要说明清楚。Individual.Smoking
  349. --UPDATE shanglifeecif.Individual si1 SET si1.label13 = (SELECT si2.Smoking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  350. --Label14:todo:无来源,逻辑需要说明清楚。Individual.Cdiseases
  351. --Label15:todo:无来源,逻辑需要说明清楚。
  352. --Label16:todo:无来源,逻辑需要说明清楚。Individual.FMHistory
  353. --Label17:todo:无来源,逻辑需要说明清楚。Individual.Pregnancy
  354. --Label18:todo:无来源,逻辑需要说明清楚。
  355. --Label19:保留暂不实现
  356. --Label20:todo:无来源,逻辑需要说明清楚。
  357. --Label21:todo:无来源,Individual.PIncome:[0,120000],'低收入';(120000,1000000],'中产';(1000000,),'富人'
  358. --UPDATE shanglifeecif.Individual si1 SET si1.Label21 = (SELECT CASE WHEN si2.pincome >=0 AND si2.pincome<=120000 THEN '低收入' WHEN si2.pincome >120000 AND si2.pincome<=1000000 THEN '中产' WHEN si2.pincome > 1000000 THEN '富人' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  359. --Label22:todo:无来源,Individual.COVehicle:0,'无车';1,'1辆车';(1,),'2辆车以上'
  360. --UPDATE shanglifeecif.Individual si1 SET si1.Label22 = (SELECT CASE WHEN si2.COVehicle ==0 THEN '无车' WHEN si2.COVehicle == 1 THEN '1辆车' WHEN si2.COVehicle > 1 THEN '2辆车以上' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  361. --Label23:todo:无来源,Individual.CORP:0,'无房';1,'1套房';(1,),'2套房以上'
  362. --UPDATE shanglifeecif.Individual si1 SET si1.Label23 = (SELECT CASE WHEN si2.CORP ==0 THEN '无房' WHEN si2.CORP == 1 THEN '1套房' WHEN si2.CORP > 1 THEN '2套房以上' END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  363. --Label24:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG = '有效',若无记录则更新Individual.NOVPolicy为0,否则更新NOVPolicy为记录数。若NOVPolicy>0,则更新Individual.Label24为'持有寿险有效保单',否则更新为'未持有寿险有效保单'
  364. --第一步 更新Individual.NOVPolicy有效记录数
  365. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = (SELECT temp.cuscount FROM (SELECT nvl(count(spi.customerno),0) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno WHERE spi.appflag = '有效' GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  366. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = 0 WHERE si1.NOVPolicy IS null;
  367. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = 0 WHERE si1.noivpolicy IS null;
  368. --第二步 更新 Individual.NOIVPolicy 无效记录数
  369. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = (SELECT temp.cuscount FROM (SELECT nvl(count(spi.customerno),0) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno WHERE spi.appflag <> '有效' GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  370. --最后一步 更新标签 24
  371. UPDATE shanglifeecif.Individual si1 SET si1.label24 = (SELECT CASE WHEN nvl(si2.novpolicy,0)>0 THEN '持有寿险有效保单' ELSE '未持有寿险有效保单' END FROM shanglifeecif.individual si2 WHERE si2.indid = si1.indid);
  372. --Label25:将Individual.NOVPolicy+Individual.NOIVPolicy的值更新ndividual.Label25
  373. --UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (SELECT (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  374. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (SELECT CASE
  375. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 0 THEN '无保单'
  376. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 1 THEN '1件'
  377. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 2 THEN '2件'
  378. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 3 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 5 THEN '3-5件'
  379. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 6 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 10 THEN '6-10件'
  380. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 11 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0))<= 20 THEN '11-20件'
  381. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 21 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 50 THEN '21-50件'
  382. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) > 50 THEN '50件以上'
  383. END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  384. --Label26:InsuranceArrangement.PolicyNo = AUDIT_LN_LIST.CONTNO,以AUDIT_LN_LIST.LNMONEY更新InsuranceArrangement.LoanMoney,以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),若无记录更新Individual.Label26为Null,若LoanMoney>0则更新Individual.Label26为'有贷款',否则更新为'无贷款'
  385. --第一步 以AUDIT_LN_LIST.LNMONEY更新InsuranceArrangement.LoanMoney
  386. UPDATE shanglifeecif.insurancearrangement sig SET sig.LoanMoney =(SELECT temp.lnmoney FROM (SELECT sall.contno,sum(sall.lnmoney) lnmoney FROM audit_ln_list sall GROUP BY sall.contno) temp WHERE temp.contno = sig.policyno);
  387. --第二步 以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID)
  388. --SELECT sig.applicantid,sum(sig.loanmoney) loanmoney FROM shanglifeecif.insurancearrangement sig GROUP BY sig.applicantid
  389. UPDATE shanglifeecif.Individual si1 SET si1.Label26 =(SELECT CASE WHEN temp.loanmoney > 0 THEN '有贷款' WHEN temp.loanmoney = 0 THEN '无贷款' ELSE NULL END FROM (SELECT sig.applicantid,sum(sig.loanmoney) loanmoney FROM shanglifeecif.insurancearrangement sig GROUP BY sig.applicantid) temp WHERE si1.indid = temp.applicantid);
  390. --Label27:todo:无来源,逻辑需要说明清楚。
  391. --lable_27 志广说只用判断有极短意外险不用判断仅有
  392. UPDATE shanglifeecif.Individual si1 SET si1.Label27 = (
  393. SELECT
  394. CASE
  395. WHEN temp.cnt >0 THEN
  396. '有极短意外险'
  397. END
  398. FROM
  399. (
  400. SELECT
  401. count(1) cnt,
  402. policy.customerno
  403. FROM
  404. policy_information policy
  405. where
  406. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  407. and
  408. policy.riskperiod='短期险'
  409. and
  410. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  411. GROUP BY
  412. policy.customerno
  413. ) temp
  414. WHERE
  415. temp.customerno = si1.scustid
  416. );
  417. --2233条记录
  418. --Label28:保留暂不实现
  419. --Label29:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表(CUSTOMERNO),POLICY_INFORMATION.APPFLAG='有效' and POLICY_INFORMATION.PAYINTV='趸缴',若有记录则更新Individual.NOSPInsurance和本标签为'有趸交保单'
  420. UPDATE shanglifeecif.Individual si1 SET si1.label29 =
  421. (SELECT CASE WHEN temp.cnum>0 THEN '有趸交保单' END FROM (SELECT count(1) cnum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.APPFLAG = '有效' AND spi.PAYINTV = '趸缴' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  422. UPDATE shanglifeecif.Individual si1 SET si1.NOSPInsurance =
  423. (SELECT CASE WHEN temp.cnum>0 THEN '有趸交保单' END FROM (SELECT count(1) cnum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.APPFLAG = '有效' AND spi.PAYINTV = '趸缴' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  424. --Label30:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.ISelf为NULL,若有记录且RELATIONTOAPPNT仅为'本人'则若无记录则更新Individual.ISelf为'仅本人投保',若有记录且RELATIONTOAPPNT不为'本人'则若无记录则更新Individual.ISelf为'本人未投保',否则更新Individual.ISelf为'本人已投保'
  425. --UPDATE shanglifeecif.Individual si1 SET si1.iself = (SELECT CASE WHEN temp.snum>0 THEN '本人已投保' WHEN temp.snum=0 THEN '本人未投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  426. --UPDATE shanglifeecif.Individual si1 SET si1.iself = (SELECT CASE WHEN temp.snum=0 AND si1.iself ='本人已投保' THEN '仅本人投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  427. UPDATE shanglifeecif.Individual si1 SET si1.label30 = (SELECT CASE WHEN temp.snum>0 THEN '本人已投保' WHEN temp.snum=0 THEN '本人未投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  428. UPDATE shanglifeecif.Individual si1 SET si1.label30 = (SELECT CASE WHEN temp.snum=0 AND si1.label30 ='本人已投保' THEN '仅本人投保' END FROM (SELECT nvl(count(spi.customerno),null) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '本人' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  429. --label31 以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Iparent为NULL,若有记录且RELATIONTOAPPNT仅为'父母'则若无记录则更新Individual.Iparent为'仅父母投保',若有记录且RELATIONTOAPPNT不为'父母'则若无记录则更新Individual.Iparent为'父母未投保',否则更新Individual.Iparent为'父母已投保'
  430. --UPDATE shanglifeecif.Individual si1 SET si1.Iparent = (SELECT CASE WHEN temp.snum > 0 THEN '父母已投保' WHEN temp.snum=0 THEN '父母未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN shanghailifeecif.policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  431. --UPDATE shanglifeecif.Individual si1 SET si1.Iparent = (SELECT CASE WHEN temp.snum=0 AND si1.Iparent = '父母已投保' THEN '仅父母投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  432. UPDATE shanglifeecif.Individual si1 SET si1.label31 = (SELECT CASE WHEN temp.snum > 0 THEN '父母已投保' WHEN temp.snum=0 THEN '父母未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  433. UPDATE shanglifeecif.Individual si1 SET si1.label31 = (SELECT CASE WHEN temp.snum=0 AND si1.label31 = '父母已投保' THEN '仅父母投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '父母' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  434. --Label32:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.IChildren为NULL,若有记录且RELATIONTOAPPNT仅为'子女'则若无记录则更新Individual.IChildren为'仅子女投保',若有记录且RELATIONTOAPPNT不为'子女'则若无记录则更新Individual.IChildren为'子女未投保',否则更新Individual.IChildren为'子女已投保'
  435. --UPDATE shanglifeecif.Individual si1 SET si1.IChildren = (SELECT CASE WHEN temp.snum>0 THEN '子女已投保' WHEN temp.snum=0 THEN '子女未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  436. --UPDATE shanglifeecif.Individual si1 SET si1.IChildren = (SELECT CASE WHEN temp.snum=0 AND si1.IChildren = '子女已投保' THEN '仅子女投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  437. UPDATE shanglifeecif.Individual si1 SET si1.label32 = (SELECT CASE WHEN temp.snum>0 THEN '子女已投保' WHEN temp.snum=0 THEN '子女未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  438. UPDATE shanglifeecif.Individual si1 SET si1.label32 = (SELECT CASE WHEN temp.snum=0 AND si1.label32 = '子女已投保' THEN '仅子女投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  439. --Label33:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Imate为NULL,若有记录且RELATIONTOAPPNT仅为'配偶'则若无记录则更新Individual.Imate为'仅配偶投保',若有记录且RELATIONTOAPPNT不为'配偶'则若无记录则更新Individual.Imate为'配偶未投保',否则更新Individual.Imate为'配偶已投保'
  440. --UPDATE shanglifeecif.Individual si1 SET si1.Imate = (SELECT CASE WHEN temp.snum>0 THEN '配偶已投保' WHEN temp.snum=0 THEN '配偶未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  441. --UPDATE shanglifeecif.Individual si1 SET si1.Imate = (SELECT CASE WHEN temp.snum=0 AND si1.Imate = '配偶已投保' THEN '仅配偶投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  442. UPDATE shanglifeecif.Individual si1 SET si1.label33 = (SELECT CASE WHEN temp.snum>0 THEN '配偶已投保' WHEN temp.snum=0 THEN '配偶未投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt = '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  443. UPDATE shanglifeecif.Individual si1 SET si1.label33 = (SELECT CASE WHEN temp.snum=0 AND si1.label33 = '配偶已投保' THEN '仅配偶投保' END FROM (SELECT count(spi.customerno) snum,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno AND spi.relationtoappnt <> '子女' GROUP BY spi.customerno) temp WHERE temp.customerno =si1.scustid);
  444. --Label34:保留暂不实现
  445. --Label35:保留暂不实现
  446. --Label36:保留暂不实现
  447. --Label37:保留暂不实现
  448. --Label38:保留暂不实现
  449. --Label39:保留暂不实现
  450. --Label40:保留暂不实现
  451. --Label41:保留暂不实现
  452. --Label42:保留暂不实现
  453. --Label43:todo:逻辑需要说明清楚(到上游源表和字段)。
  454. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  455. SELECT
  456. CASE
  457. WHEN temp.cnt >0 THEN
  458. '有1年期短险保单'
  459. END
  460. FROM
  461. (
  462. SELECT
  463. count(1) cnt,
  464. policy.customerno
  465. FROM
  466. policy_information policy
  467. where
  468. policy.SECURITY in('1年','6月','180天')
  469. and
  470. policy.riskperiod='短期险'
  471. and
  472. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  473. GROUP BY
  474. policy.customerno
  475. ) temp
  476. WHERE
  477. temp.customerno = si1.scustid
  478. );
  479. --Label44:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG<>'有效',若无记录则更新Individual.NOIVPolicy为0,否则更新NOIVPolicy为记录数。若NOIVPolicy>0,则更新Individual.Label44为'有失效保单',否则更新为'无失效保单'
  480. UPDATE shanglifeecif.Individual si1 SET si1.label44 = (SELECT CASE WHEN si2.noivpolicy>0 THEN '有失效保单' END FROM shanglifeecif.individual si2 WHERE si2.indid = si1.indid);
  481. --LABEL45:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且riskperiod='长期险',若无记录则更新Individual.Label45为NULL,若有记录且paycount= payendyear则更新Individual.Label45为'有缴费期满长险保单',否则更新Individual.Label45为'无缴费期满长险保单'
  482. UPDATE shanglifeecif.Individual si1 SET si1.label45 = (SELECT CASE WHEN temp.cuscount IS NULL THEN NULL WHEN temp.cuscount>0 THEN '有缴费期满长险保单' ELSE '无缴费期满长险保单' END FROM (SELECT count(spi.customerno) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno WHERE spi.riskperiod='长期险' AND spi.paycount = spi.payendyear GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  483. --Label46:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label46为NULL,若有记录且paycount= payendyear则更新Individual.Label46为'有续期缴费的保单',否则更新Individual.Label46为'无有续期缴费的保单'
  484. UPDATE shanglifeecif.Individual si1 SET si1.label46 = (SELECT CASE WHEN temp.cuscount IS NULL THEN NULL WHEN temp.cuscount>0 THEN '有续期缴费的保单' ELSE '无有续期缴费的保单' END FROM (SELECT count(spi.customerno) cuscount,spi.customerno FROM shanglifeecif.Individual si1 LEFT JOIN policy_information spi ON si1.scustid = spi.customerno WHERE spi.paycount = spi.payendyear GROUP BY spi.customerno) temp WHERE temp.customerno = si1.scustid);
  485. --Label47:todo:逻辑需要说明清楚(到上游源表和字段)。
  486. --Label48:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最早日期(PADate)更新Individual.FADate
  487. -- UPDATE shanglifeecif.Individual si1 SET si1.FADate = (SELECT '首次投保日期' || temp.padate FROM (SELECT min(si.PADate) padate,si.applicantid FROM shanglifeecif.insurancearrangement si GROUP BY si.applicantid) temp WHERE temp.applicantid = si1.indid);
  488. UPDATE shanglifeecif.Individual si1 SET si1.label48 = (SELECT '首次投保日期' || temp.padate FROM (SELECT min(si.PADate) padate,si.applicantid FROM shanglifeecif.insurancearrangement si GROUP BY si.applicantid) temp WHERE temp.applicantid = si1.indid);
  489. --Label49:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最近日期(PADate)更新Individual.LAPPDate,最后用当前日期减去Individual.LAPPDate更新Label49
  490. UPDATE shanglifeecif.Individual si1 SET si1.LAPPDate = (SELECT temp.PADate FROM (SELECT min(si.PADate) padate,si.applicantid FROM shanglifeecif.insurancearrangement si GROUP BY si.applicantid) temp WHERE temp.applicantid = si1.indid);
  491. UPDATE shanglifeecif.Individual si1 SET si1.Label49 = (SELECT '最后一次投保距今' || TRUNC(months_between(sysdate(), si2.LAPPDate)/12) || '天' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  492. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel
  493. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel,并更新此标签为:'最近保单'+Individual.LPChannel
  494. UPDATE shanglifeecif.Individual si1 SET si1.LPChannel = (SELECT temp.agentchannel FROM (SELECT si.agentchannel,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate DESC) rd FROM shanglifeecif.InsuranceArrangement si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  495. UPDATE shanglifeecif.Individual si1 SET si1.Label50 = (SELECT '最近保单' || si1.LPChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  496. --Label51:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentOrg更新Individual.LPOrg,并更新此标签为:'最近'+Individual.LPOrg+'机构'
  497. UPDATE shanglifeecif.Individual si1 SET si1.LPOrg = (SELECT temp.AgentOrg FROM (SELECT si.AgentOrg,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate DESC) rd FROM shanglifeecif.InsuranceArrangement si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  498. UPDATE shanglifeecif.Individual si1 SET si1.Label51 = (SELECT '最近' || si2.LPOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid) ;
  499. --Label52:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentChannel更新Individual.FAChannel
  500. UPDATE shanglifeecif.Individual si1 SET si1.FAChannel = (SELECT tt.agentchannel FROM (SELECT si.agentchannel,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si ) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  501. UPDATE shanglifeecif.Individual si1 SET si1.Label52 = (SELECT '首单' || si2.FAChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  502. --Label53:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentOrg更新Individual.FAOrg
  503. UPDATE shanglifeecif.Individual si1 SET si1.FAOrg = (SELECT tt.AgentOrg FROM (SELECT si.AgentOrg,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  504. UPDATE shanglifeecif.Individual si1 SET si1.Label53 = (SELECT '首单' || si2.FAOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  505. --Label54:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的PolicyState更新Individual.LPState
  506. UPDATE shanglifeecif.Individual si1 SET si1.LPState = (SELECT tt.PolicyState FROM (SELECT si.PolicyState,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.PADate ASC) rd FROM shanglifeecif.insurancearrangement si) tt WHERE tt.applicantid = si1.indid AND tt.rd = 1);
  507. --Label55 :Label55:由于上游保全类型信息分散在AUDIT_EDORLIST.EDORNAME和edorinfo.edortype 中,同时edorinfo.edortype为code需要转为string(具体映射见下)。以上游客户号(Individual.SCustID)分别查询AUDIT_EDORLIST表和edorinfo表,取保全生效日期最近的记录的更新的保全类型更新Individual.LPOSType。todo:edorinfo.edortype为code,需要转为string,edorinfo中需要增加上游客户号,否则需要多一次关联,建议大数据平台处理完成。
  508. --AUDIT_EDORLIST表里没有上游客户号,UPDATE shanglifeecif.Individual si1 SET si1.LPOSType =(SELECT ae.edorname FROM shanghailifeecif.audit_edorlist ae )
  509. UPDATE shanglifeecif.Individual si1 SET si1.lpostype = (SELECT tt.edortype FROM ( SELECT temp.scustid,temp.edortype,temp.edorvalidate,row_number()OVER(PARTITION BY temp.scustid ORDER BY temp.edorvalidate DESC) rd FROM ((SELECT si2.scustid,sae.edorname edortype,sae.edorvalidate FROM shanglifeecif.Individual si2
  510. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  511. LEFT JOIN shanghailifeecif.audit_edorlist sae ON sae.contno = spi.contno)
  512. UNION
  513. ( SELECT si2.scustid,se.edortype,se.edorappdate edorvalidate FROM shanglifeecif.Individual si2
  514. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  515. LEFT JOIN shanghailifeecif.edorinfo se ON se.contno = spi.contno)) temp) tt WHERE tt.scustid = si1.scustid AND tt.rd = 1);
  516. --Label56:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询INSURANCEINFO表 and INSURANCEINFO.APPFLAG = '已退保',若有记录则更新此标签为'有退保保单'
  517. UPDATE shanglifeecif.Individual si1 SET si1.Label56 =
  518. (SELECT CASE WHEN temp.cunm > 0 THEN '有退保保单' END FROM
  519. (
  520. SELECT count(1) cunm,si2.scustid FROM shanglifeecif.Individual si2
  521. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  522. LEFT JOIN shanghailifeecif.INSURANCEINFO sio ON spi.CONTNO = sio.CONTNO
  523. WHERE sio.APPFLAG = '已退保' GROUP BY si2.scustid
  524. ) temp WHERE temp.scustid = si1.scustid);
  525. --Label57:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询AUDIT_CLAIM_INSURANCE表,取AUDIT_CLAIM_INSURANCE.RGTDATE最近对应的AUDIT_CLAIM_INSURANCE.RISKTYPE更新此标签。todo:实际数据仅有寿险、意外险、健康险,取值是否正确?
  526. UPDATE shanglifeecif.Individual si1 SET si1.Label57 =
  527. (SELECT temp.RISKTYPE FROM (
  528. SELECT si2.scustid,saci.RISKTYPE,row_number()OVER(PARTITION BY si2.scustid ORDER BY saci.RGTDATE DESC) rd FROM shanglifeecif.Individual si2
  529. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  530. LEFT JOIN shanghailifeecif.audit_claim_insurance saci ON saci.CONTNO = spi.CONTNO
  531. ) temp WHERE si1.scustid = temp.scustid AND temp.rd = 1);
  532. --Label59 :以个体ID(Individual.IndID)查询InsuranceClaimThread表(Individual.IndID=InsuranceClaimThread.ApplicantID), 以最近日期(CNDate)的ClaimCaseStatus更新Individual.CNStatus
  533. UPDATE shanglifeecif.Individual si1 SET si1.CNStatus =(SELECT temp.ClaimCaseStatus FROM (SELECT si.ClaimCaseStatus,si.applicantid,row_number()OVER(PARTITION BY si.applicantid ORDER BY si.CNDate DESC) rd FROM shanglifeecif.insuranceclaimthread si) temp WHERE temp.applicantid = si1.indid AND temp.rd = 1);
  534. --Label60:保留暂不实现
  535. --Label61:todo:逻辑需要说明清楚(到上游源表和字段)。
  536. --Label62:保留暂不实现
  537. --Label63:todo:逻辑需要说明清楚(到上游源表和字段)。
  538. --Label64:todo:逻辑需要说明清楚(到上游源表和字段)。
  539. --Label65:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label65为NULL,若仅一条记录则更新Individual.Label65为'一单寿险客户'
  540. UPDATE shanglifeecif.Individual si1 SET si1.Label65 =
  541. (SELECT CASE WHEN tt.cnum = 1 THEN '一单寿险客户' END FROM (SELECT nvl(count(spi.customerno),0) cnum,max(si2.indid) indid FROM shanghailifeecif.policy_information spi LEFT JOIN shanglifeecif.Individual si2 ON si2.scustid = spi.customerno GROUP BY spi.customerno) tt WHERE si1.indid = tt.indid);
  542. --Label66:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label66为NULL,若 paycount= payendyear更新Individual.Label66为'缴费期满客户',否则更新为'非缴费期满客户
  543. UPDATE shanglifeecif.Individual si1 SET si1.Label66 =
  544. (SELECT CASE WHEN tt.cnum >0 THEN '缴费期满客户' END FROM (SELECT nvl(count(spi.customerno),0) cnum,max(si2.indid) indid FROM shanghailifeecif.policy_information spi LEFT JOIN shanglifeecif.Individual si2 ON si2.scustid = spi.customerno and spi.paycount= spi.payendyear GROUP BY spi.customerno) tt WHERE si1.indid = tt.indid);
  545. --Label67:若Individual.Birthday的月日与上海人寿司庆日月日相同,则设置此标签为:'生日与司庆日同天'。todo:需要确定司庆日是几月几号
  546. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = (SELECT CASE WHEN substr(si2.birthday,6,10) = '02-15' THEN '生日与司庆日同天' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  547. --Label68:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表, and POLICY_INFORMATION.APPFLAG='有效',若有记录则设置此标签为'持有有效保单',否则则设置为'未持有有效保单'
  548. UPDATE shanglifeecif.Individual si1 SET si1.Label68 = (SELECT CASE WHEN si2.NOVPolicy>0 THEN '持有有效保单' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  549. --Label69:Individual.CustClass,逻辑见上(一.7)
  550. UPDATE shanglifeecif.Individual si1 SET si1.Label69 = (SELECT si2.CustClass FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  551. --Label70:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Scenario更新此标签
  552. UPDATE shanglifeecif.Individual si1 SET si1.Label70 = (SELECT temp.Scenario FROM (SELECT sp.Scenario,sp.PartyID,row_number()OVER(PARTITION BY sp.PartyID ORDER BY sp.SDate DESC) rd FROM shanglifeecif.PartyTimeLine sp) temp WHERE si1.indid = temp.PartyID AND temp.rd = 1);
  553. --Label71:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Channel更新此标签
  554. UPDATE shanglifeecif.Individual si1 SET si1.Label71 = (SELECT temp.Channel FROM (SELECT sp.Channel,sp.PartyID,row_number()OVER(PARTITION BY sp.PartyID ORDER BY sp.SDate DESC) rd FROM shanglifeecif.PartyTimeLine sp) temp WHERE si1.indid = temp.PartyID AND temp.rd = 1);
  555. --Label72:保留暂不实现
  556. --Label73
  557. --Label74
  558. --Label75
  559. --Label76
  560. --Label77:Individual.Birthday 距离当前日期5天内,更新Individual.Label77为'本人生日临近',否则为NULL
  561. UPDATE shanglifeecif.Individual si1 SET si1.Label77 = (SELECT CASE WHEN DATEDIFF(sysdate(), si2.birthday)<=5 THEN '本人生日临近' END FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  562. --Label78:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'父亲'或'母亲'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label78为'父母生日临近',否则为NULL
  563. UPDATE shanglifeecif.Individual si1 SET si1.Label78 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '父母生日临近' END FROM (
  564. SELECT sis.indid2 FROM shanglifeecif.Individual si2 LEFT JOIN shanglifeecif.IndRelationShip sis ON si2.indid = sis.indid1 WHERE (sis.role2 = '父亲' or sis.role2 = '母亲') GROUP BY sis.indid2) tt WHERE si1.indid = tt.indid2);
  565. --Label79:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'儿子'或'女儿'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label79为'子女生日临近',否则为NULL
  566. UPDATE shanglifeecif.Individual si1 SET si1.Label79 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '子女生日临近' END FROM (
  567. SELECT sis.indid2 FROM shanglifeecif.Individual si2 LEFT JOIN shanglifeecif.IndRelationShip sis ON si2.indid = sis.indid1 WHERE (sis.role2 = '儿子' or sis.role2 = '女儿') GROUP BY sis.indid2) tt WHERE si1.indid = tt.indid2);
  568. --Label96:根据Individual.Birthday算出当前年龄,如果50<=年龄<60,则更新Individual.Label96为'大龄',否则为NULL
  569. UPDATE shanglifeecif.Individual si1 SET si1.Label96 = (SELECT CASE WHEN TRUNC(months_between(sysdate, si2.birthday)/12)>=50 AND TRUNC(months_between(sysdate, si2.birthday)/12)<60 THEN '大龄' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  570. --Label97:根据Individual.Birthday算出当前年龄,如果60<=年龄,则更新Individual.Label97为'高龄',否则为NULL
  571. UPDATE shanglifeecif.Individual si1 SET si1.Label97 = (SELECT CASE WHEN TRUNC(months_between(sysdate, si2.birthday)/12)>=60 THEN '高龄' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  572. --Label98:根据Individual.Occupation,若为记者、律师、公务员、媒体、金融行业,则更新Individual.Label98为'敏感职业',否则为NULL
  573. UPDATE shanglifeecif.Individual si1 SET si1.Label98 = (SELECT CASE WHEN si2.occupation = '记者' OR si2.occupation = '律师' OR si2.occupation = '公务员' OR si2.occupation = '媒体' OR si2.occupation = '金融行业' THEN '敏感职业' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  574. --Label109:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='报案'且 InsuranceClaimThread.CNDate距当前日期超过7天,则更新Individual.Label109为'理赔报案追踪'
  575. UPDATE shanglifeecif.Individual si1 SET si1.Label109 = (SELECT CASE WHEN count(1)>0 THEN '理赔报案追踪' END FROM shanglifeecif.insuranceclaimthread sit WHERE si1.indid = sit.applicantid AND sit.claimstatus = '报案' AND DATEDIFF(sysdate(), sit.CNDate)>7);
  576. --Label110:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='受理' or '立案',则更新Individual.Label110为'理赔处理中'
  577. UPDATE shanglifeecif.Individual si1 SET si1.Label110 = (SELECT CASE WHEN count(1)>0 THEN '理赔处理中' END FROM shanglifeecif.insuranceclaimthread sit WHERE si1.indid = sit.applicantid AND (sit.claimstatus = '受理' OR sit.claimstatus = '立案'));
  578. --Label112:先以个体ID(Individual.IndID)得到InsuranceArrangement.PolicyNo,再以此关联AUDIT_EDORLIST,若有记录且保全状态EDORSTATE<>'确认生效' and '复核终止' and '强制终止',则更新Individual.Label111为'保全处理中'
  579. UPDATE shanglifeecif.Individual si1 SET si1.Label112 = (SELECT CASE WHEN nvl(count(sae.contno),0) > 0 THEN '保全处理中' END FROM (SELECT si1.indid indid,max(sia.policyno) policyno FROM shanglifeecif.Individual si1 LEFT JOIN shanglifeecif.InsuranceArrangement sia ON si1.indid = sia.applicantid GROUP BY si1.indid) tt LEFT JOIN shanghailifeecif.audit_edorlist sae ON sae.contno = tt.policyno AND sae.edorstate <> '确认生效' AND sae.edorstate <> '复核终止' AND sae.edorstate <> '强制终止' WHERE si1.indid = tt.indid);
  580. UPDATE shanglifeecif.Individual si1 SET si1.Label70 =
  581. (SELECT temp.scenario FROM (
  582. SELECT qi.applicantid,qp.threadid,qp.scenario,row_number()OVER(PARTITION BY qp.threadid ORDER BY qp.created_time DESC) rd FROM qxp.partytimeline qp
  583. LEFT JOIN qxp.insurancearrangement qi ON qp.threadid = qi.policyno
  584. WHERE rd = 1
  585. ) temp WHERE temp.applicantid = si1.indid)
  586. --注册官微
  587. UPDATE shanglifeecif.Individual si1 SET si1.Label74 = (SELECT CASE WHEN COUNT(1)>0 THEN '注册官微' END FROM shanghailifeecif.wx_list wl WHERE wl.certificate_no = si1.idcard)
  588. --长通话逻辑contnos为客户的保单号select (select lo.call_length from ucc_rms_recorderlog lo where lo.call_id=m.call_id) as lenth from cc_record_main mwhere m.contnos='2019082000110188'
  589. UPDATE shanglifeecif.Individual si1 SET si1.label10 =
  590. (SELECT CASE WHEN tt.avgCallLenth>600 THEN '长通话' END FROM (
  591. SELECT temp.contnos,(temp.lenth/temp.callNum) as avgCallLenth,qi.applicantid FROM(
  592. select (select lo.call_length from shanghailifeecif.ucc_rms_recorderlog lo where lo.call_id=m.call_id) as lenth,count(1) AS callNum,m.contnos from shanghailifeecif.cc_record_main m
  593. GROUP BY m.contnos
  594. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.contnos = qi.policyno) tt WHERE tt.applicantid = si1.indid)
  595. --要求较多,每次来电均下转办单
  596. UPDATE shanglifeecif.Individual si1 SET si1.label103 =
  597. -- (SELECT '要求多' FROM shanghailifeecif.cc_swfflowmain swf
  598. -- LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  599. -- WHERE swf.flowid LIKE '%ZX%' AND si1.indid = qi.applicantid)
  600. (
  601. SELECT CASE WHEN t.callNum==t.swf_num THEN '要求较多' END FROM (
  602. SELECT count(*) AS callNum,srm.contnos,(SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  603. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  604. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  605. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  606. WHERE si1.indid = qi.applicantid
  607. )
  608. UPDATE shanglifeecif.Individual si1 SET si1.label104 =
  609. --(SELECT '易投诉升级' FROM shanghailifeecif.cc_swfflowmain swf
  610. --LEFT JOIN shanghailifeecif.cc_swf_sort scc ON scc.complaintProject = swf.id
  611. --LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  612. -- WHERE swf.flowid LIKE '%ZX%' AND scc.idname='投诉' AND si1.indid = qi.applicantid)
  613. (
  614. SELECT CASE WHEN t.callNum==t.swf_num THEN '易投诉升级' END FROM (
  615. SELECT count(*) AS callNum,srm.contnos,
  616. (SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  617. LEFT JOIN shanghailifeecif.cc_swf_sort scs ON swf.complaintproject = scs.id
  618. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  619. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  620. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  621. WHERE si1.indid = qi.applicantid
  622. )
  623. UPDATE shanglifeecif.Individual si1 SET si1.label105 =
  624. (SELECT '高频投诉' FROM (
  625. select count(1) as comnum,c.productno,DATEDIFF(max(c.inserttime),min(c.inserttime)) dayNum from shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  626. ) temp
  627. LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = temp.productno
  628. WHERE temp.comnum >= 2 AND temp.dayNum <180 AND si1.indid = qi.applicantid
  629. )
  630. SELECT c.productno,c.inserttime FROM shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  631. UPDATE shanglifeecif.Individual si1 SET si1.label106 =
  632. /*(SELECT CASE temp.complaintsSource when '914' then '重大投诉'
  633. when '919' then '重大投诉'
  634. when '915' then '重大投诉' END,qi.applicantid FROM (
  635. select c.complaintsSource,cd.productno from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd
  636. where cd.complaintsid=c.complaintsid
  637. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.productno = qi.policyno WHERE qi.applicantid = si1.indid)
  638. */
  639. (SELECT CASE WHEN tt.complaintsSource LIKE '%914%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%915%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%919%' THEN '重大投诉' END FROM (
  640. select group_concat(c.complaintsSource,',') AS complaintsSource,qi.applicantid from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd,qxp.insurancearrangement qi
  641. where cd.complaintsid=c.complaintsid AND qi.policyno = cd.productno
  642. GROUP BY qi.applicantid
  643. ) tt WHERE tt.applicantid = si1.indid)
  644. --lable_67 司庆日
  645. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = '司庆日' where birthday like '%-02-05';
  646. END ;