客户标签koucx20210126.sql 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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.NOVPolicy有效记录数
  45. 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);
  46. --第二步 更新 Individual.NOIVPolicy 无效记录数
  47. 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);
  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 (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) = 0 THEN '无保单'
  52. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) = 1 THEN '1件'
  53. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) = 2 THEN '2件'
  54. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 3 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 5 THEN '3-5件'
  55. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 6 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 10 THEN '6-10件'
  56. WHEN nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0) >= 11 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 20 THEN '11-20件'
  57. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 21 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 50 THEN '21-50件'
  58. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) > 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. UPDATE shanglifeecif.Individual si1 SET si1.Label69 = (
  168. SELECT
  169. CASE si2.CustClass
  170. WHEN 0 THEN '无'
  171. WHEN 1 THEN '钻石'
  172. WHEN 2 THEN '白金'
  173. WHEN 3 THEN '黄金'
  174. WHEN 4 THEN '普通'
  175. END
  176. FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  177. --Label70:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Scenario更新此标签
  178. 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);
  179. --Label71:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Channel更新此标签
  180. 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);
  181. --Label72:保留暂不实现
  182. --Label73
  183. --Label74
  184. --Label75
  185. --Label76
  186. --Label77:Individual.Birthday 距离当前日期5天内,更新Individual.Label77为'本人生日临近',否则为NULL
  187. 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);
  188. --Label78:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'父亲'或'母亲'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label78为'父母生日临近',否则为NULL
  189. UPDATE shanglifeecif.Individual si1 SET si1.Label78 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '父母生日临近' END FROM (
  190. 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);
  191. --Label79:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'儿子'或'女儿'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label79为'子女生日临近',否则为NULL
  192. UPDATE shanglifeecif.Individual si1 SET si1.Label79 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '子女生日临近' END FROM (
  193. 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);
  194. --Label96:根据Individual.Birthday算出当前年龄,如果50<=年龄<60,则更新Individual.Label96为'大龄',否则为NULL
  195. 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);
  196. --Label97:根据Individual.Birthday算出当前年龄,如果60<=年龄,则更新Individual.Label97为'高龄',否则为NULL
  197. 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);
  198. --Label98:根据Individual.Occupation,若为记者、律师、公务员、媒体、金融行业,则更新Individual.Label98为'敏感职业',否则为NULL
  199. 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);
  200. UPDATE shanglifeecif.Individual si1 SET si1.Label98 = (SELECT CASE WHEN si2.occupation like '%记者%' OR si2.occupation like '%律师%' OR si2.occupation like '%公务员%' OR si2.occupation like '%媒体%' OR si2.occupation like '%金融行业%' THEN '敏感职业' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  201. --Label109:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='报案'且 InsuranceClaimThread.CNDate距当前日期超过7天,则更新Individual.Label109为'理赔报案追踪'
  202. 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);
  203. --Label110:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='受理' or '立案',则更新Individual.Label110为'理赔处理中'
  204. 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 = '立案'));
  205. --Label112:先以个体ID(Individual.IndID)得到InsuranceArrangement.PolicyNo,再以此关联AUDIT_EDORLIST,若有记录且保全状态EDORSTATE<>'确认生效' and '复核终止' and '强制终止',则更新Individual.Label111为'保全处理中'
  206. 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);
  207. UPDATE shanglifeecif.Individual si1 SET si1.Label70 =
  208. (SELECT temp.scenario FROM (
  209. 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
  210. LEFT JOIN qxp.insurancearrangement qi ON qp.threadid = qi.policyno
  211. WHERE rd = 1
  212. ) temp WHERE temp.applicantid = si1.indid)
  213. --注册官微
  214. 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)
  215. --长通话逻辑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'
  216. UPDATE shanglifeecif.Individual si1 SET si1.Label101 = (
  217. SELECT '长通话' FROM (
  218. SELECT
  219. t.contnos,
  220. row_number()OVER(PARTITION BY p.customerno) rn,
  221. p.customerno
  222. FROM (
  223. SELECT (sum(lo.call_length)/count(*)) AS avgcalltime,m.contnos from cc_record_main m
  224. LEFT JOIN ucc_rms_recorderlog lo ON m.call_id = lo.call_id
  225. WHERE m.contnos IS NOT NULL AND lo.call_length IS NOT NULL
  226. GROUP BY m.contnos
  227. ) t LEFT JOIN policy_information p ON t.contnos = p.contno
  228. WHERE t.avgcalltime>600
  229. ) temp WHERE temp.customerno IS NOT NULL AND temp.rn = 1 AND si1.scustid = temp.customerno
  230. );
  231. --要求较多,每次来电均下转办单
  232. UPDATE shanglifeecif.Individual si1 SET si1.Label103 = (SELECT "要求较多" FROM (
  233. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno) rn
  234. FROM (
  235. SELECT max(t.mnum) AS mnum,f.policyno,count(*) AS fnum FROM (
  236. SELECT count(*) AS mnum,m.contnos FROM cc_record_main m WHERE m.contnos IS NOT null
  237. GROUP BY m.contnos
  238. ) t LEFT JOIN cc_swfflowmain f ON t.contnos = f.policyno
  239. WHERE f.flowid LIKE 'ZX%' AND f.policyno IS NOT NULL
  240. GROUP BY f.policyno
  241. ) temp LEFT JOIN policy_information p ON temp.policyno = p.contno
  242. WHERE temp.fnum = temp.mnum
  243. ) tt WHERE tt.rn = 1 AND tt.customerno IS NOT NULL AND si1.scustid = tt.customerno)
  244. --易投诉升级
  245. UPDATE shanglifeecif.Individual si1 SET si1.Label104 = (SELECT "易投诉升级" FROM (
  246. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno) rn
  247. FROM (
  248. SELECT max(t.mnum) AS mnum,f.policyno,count(*) AS fnum FROM (
  249. SELECT count(*) AS mnum,m.contnos FROM cc_record_main m WHERE m.contnos IS NOT null
  250. GROUP BY m.contnos
  251. ) t LEFT JOIN cc_swfflowmain f ON t.contnos = f.policyno
  252. LEFT JOIN cc_swf_sort r ON r.id=f.complaintProject
  253. WHERE f.flowid LIKE 'ZX%' AND r.idname='投诉' and f.policyno IS NOT NULL
  254. GROUP BY f.policyno
  255. ) temp LEFT JOIN policy_information p ON temp.policyno = p.contno
  256. WHERE temp.fnum = temp.mnum
  257. ) tt WHERE tt.rn = 1 AND tt.customerno IS NOT NULL AND si1.scustid = tt.customerno)
  258. --高频投诉
  259. UPDATE shanglifeecif.Individual si1 SET si1.Label105 = '高频投诉' WHERE si1.scustid in
  260. (SELECT p.customerno FROM policy_information p WHERE p.contno IN
  261. (SELECT temp.productno FROM (
  262. SELECT t.productno,t.sinserttime,
  263. (SELECT tt.inserttime FROM (SELECT cad.inserttime,row_number()OVER(PARTITION BY cad.productno ORDER BY cad.inserttime) rownum,cad.productno FROM cc_action_complaints ca,cc_action_data_complaints cad
  264. WHERE cad.complaintsid=ca.complaintsid AND cad.productno IS NOT NULL) tt WHERE tt.productno = t.productno AND tt.rownum = t.rn+1) AS esinserttime
  265. FROM
  266. (
  267. select cd.productno,row_number()OVER(PARTITION BY cd.productno ORDER BY cd.inserttime) rn,cd.inserttime AS sinserttime
  268. from cc_action_complaints c,cc_action_data_complaints cd WHERE cd.complaintsid=c.complaintsid AND cd.productno IS NOT NULL
  269. ) t
  270. ) temp WHERE temp.esinserttime IS NOT NULL AND DATEDIFF(temp.esinserttime,temp.sinserttime) < 180))
  271. SELECT c.productno,c.inserttime FROM shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  272. --重大投诉
  273. UPDATE shanglifeecif.Individual si1 SET si1.Label106 = (
  274. SELECT
  275. CASE
  276. WHEN tt.complaintsSource LIKE '%保监会%' THEN '重大投诉'
  277. WHEN tt.complaintsSource LIKE '%保监局%' THEN '重大投诉'
  278. WHEN tt.complaintsSource LIKE '%媒体转办%' THEN '重大投诉' END FROM (
  279. SELECT pi.customerno,max(complaintsSource) AS complaintsSource FROM (
  280. select group_concat((case c.complaintsSource
  281. when '911' then '来电'
  282. when '912' then '来访'
  283. when '913' then '来函'
  284. when '914' then '保监会转办'
  285. when '919' then '保监局转办'
  286. when '915' then '媒体转办'
  287. when '916' then '同业公会'
  288. when '917' then '其他转办'
  289. when '918' then '呼出'
  290. else c.complaintsSource END),',') as complaintsSource,p.contno from cc_action_complaints c,cc_action_data_complaints cd,policy_information p
  291. where cd.complaintsid=c.complaintsid AND p.contno = cd.productno GROUP BY p.contno
  292. ) t LEFT JOIN policy_information pi ON t.contno = pi.contno GROUP BY pi.customerno
  293. ) tt WHERE tt.customerno = si1.scustid
  294. );
  295. --高保额
  296. UPDATE shanglifeecif.Individual si1 SET si1.Label107 = '高保额' WHERE si1.scustid IN (SELECT p.customerno FROM policy_information p WHERE (p.salecom = '03' AND p.prem>30000 AND p.appflag = '有效') OR (p.salecom <> '03' AND p.prem>60000 AND p.appflag = '有效'))
  297. --理赔报案追踪
  298. UPDATE shanglifeecif.Individual si1 SET si1.Label109 = '理赔报案追踪' WHERE si1.scustid IN (SELECT p.customerno FROM policy_information p WHERE p.contno IN (SELECT c.CONTNO FROM insurance_claim c WHERE c.LLCLAIMSTATE = '报案' AND DATEDIFF(sysdate(), c.RPTDATE) <30) )
  299. --理赔处理中
  300. UPDATE shanglifeecif.Individual si1 SET si1.Label110 = '理赔处理中' WHERE
  301. si1.scustid IN (SELECT p.customerno FROM policy_information p WHERE p.contno IN
  302. (SELECT c.CONTNO FROM insurance_claim c WHERE c.LLCLAIMSTATE = '受理' or c.LLCLAIMSTATE = '立案') )
  303. --重点银行
  304. UPDATE shanglifeecif.Individual si1 SET si1.Label120 = '重点银行' WHERE
  305. si1.scustid IN (SELECT p.customerno FROM policy_information p WHERE p.salechnl LIKE '%招商%')
  306. --lable_27 志广说只用判断有极短意外险不用判断仅有
  307. UPDATE shanglifeecif.Individual si1 SET si1.Label26 = (
  308. SELECT
  309. CASE
  310. WHEN temp.cnt >0 THEN
  311. '有极短意外险'
  312. END
  313. FROM
  314. (
  315. SELECT
  316. count(1) cnt,
  317. policy.customerno
  318. FROM
  319. shanghailifeecif.policy_information policy
  320. where
  321. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  322. and
  323. policy.riskperiod='短期险'
  324. and
  325. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  326. GROUP BY
  327. policy.customerno
  328. ) temp
  329. WHERE
  330. temp.customerno = si1.scustid
  331. );
  332. --2233条记录
  333. --lable_43
  334. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  335. SELECT
  336. CASE
  337. WHEN temp.cnt >0 THEN
  338. '有1年期短险保单'
  339. END
  340. FROM
  341. (
  342. SELECT
  343. count(1) cnt,
  344. policy.customerno
  345. FROM
  346. shanghailifeecif.policy_information policy
  347. where
  348. policy.SECURITY in('1年','6月','180天')
  349. and
  350. policy.riskperiod='短期险'
  351. and
  352. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  353. GROUP BY
  354. policy.customerno
  355. ) temp
  356. WHERE
  357. temp.customerno = si1.scustid
  358. );
  359. --529354条记录
  360. --lable_67 司庆日
  361. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = '司庆日' where birthday like '%-02-05';
  362. --3615
  363. EXCEPTION
  364. WHEN HIVE_EXCEPTION THEN
  365. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  366. WHEN Others THEN
  367. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  368. END ;
  369. --更新客户标签信息
  370. CREATE OR REPLACE PROCEDURE shanglifeecif.updateIndividualLable() IS
  371. DECLARE
  372. BEGIN
  373. --label1: 无来源。Individual.Education
  374. --label2: Individual.Occupation,逻辑见上
  375. UPDATE shanglifeecif.Individual si1 SET si1.label2 = (SELECT si2.Occupation FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  376. --标签3 根据Individual.Birthday年代,更新为70后,80后等
  377. UPDATE shanglifeecif.Individual si1 SET si1.label3 = (SELECT substr(si2.birthday,3,1) || '0后' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  378. --Label4:根据Individual.Birthday算出年龄,儿童:[0,13),少年:[13,19),青年:[19,41),中年:[41,66),老年:[66,)
  379. 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);
  380. --Label5: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  381. --Label6: todo:只有收件地址(POSTAL_INSURANCE.HOMEADDRESS)且无记录
  382. --Label7:保留暂不实现
  383. --Label8:保留暂不实现
  384. --标签9 已婚,未婚 无来源。Individual.MaritalStat,查询个体关系表(IndRelationShip),RSType = '配偶',如果有记录则更新为已婚,否则更新为null
  385. 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);
  386. --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)
  387. --Label10:查询IndRelationShip,RSType='父母',首先将返回记录数更新Individual.COChild,若记录数为0,则更新本字段为'无子女',若记录数为1,则更新本字段为'1孩',若记录数大于等于2,则更新本字段为'2孩及以上'
  388. --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);
  389. 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);
  390. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (SELECT '已婚' FROM shanglifeecif.IndRelationShip sirs WHERE si1.indid = sirs.indid2 AND sirs.rstype = '配偶')
  391. --Label11:todo:无来源,逻辑需要说明清楚
  392. --Label12:todo:无来源,逻辑需要说明清楚。Individual.Drinking
  393. --UPDATE shanglifeecif.Individual si1 SET si1.label12 = (SELECT si2.Drinking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  394. --Label13:todo:无来源,逻辑需要说明清楚。Individual.Smoking
  395. --UPDATE shanglifeecif.Individual si1 SET si1.label13 = (SELECT si2.Smoking FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  396. --Label14:todo:无来源,逻辑需要说明清楚。Individual.Cdiseases
  397. --Label15:todo:无来源,逻辑需要说明清楚。
  398. --Label16:todo:无来源,逻辑需要说明清楚。Individual.FMHistory
  399. --Label17:todo:无来源,逻辑需要说明清楚。Individual.Pregnancy
  400. --Label18:todo:无来源,逻辑需要说明清楚。
  401. --Label19:保留暂不实现
  402. --Label20:todo:无来源,逻辑需要说明清楚。
  403. --Label21:todo:无来源,Individual.PIncome:[0,120000],'低收入';(120000,1000000],'中产';(1000000,),'富人'
  404. --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);
  405. --Label22:todo:无来源,Individual.COVehicle:0,'无车';1,'1辆车';(1,),'2辆车以上'
  406. --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);
  407. --Label23:todo:无来源,Individual.CORP:0,'无房';1,'1套房';(1,),'2套房以上'
  408. --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);
  409. --Label24:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG = '有效',若无记录则更新Individual.NOVPolicy为0,否则更新NOVPolicy为记录数。若NOVPolicy>0,则更新Individual.Label24为'持有寿险有效保单',否则更新为'未持有寿险有效保单'
  410. --第一步 更新Individual.NOVPolicy有效记录数
  411. 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);
  412. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = 0 WHERE si1.NOVPolicy IS null;
  413. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = 0 WHERE si1.noivpolicy IS null;
  414. --第二步 更新 Individual.NOIVPolicy 无效记录数
  415. 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);
  416. --最后一步 更新标签 24
  417. 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);
  418. --Label25:将Individual.NOVPolicy+Individual.NOIVPolicy的值更新ndividual.Label25
  419. --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);
  420. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (SELECT CASE
  421. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 0 THEN '无保单'
  422. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 1 THEN '1件'
  423. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) == 2 THEN '2件'
  424. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 3 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 5 THEN '3-5件'
  425. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 6 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 10 THEN '6-10件'
  426. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 11 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0))<= 20 THEN '11-20件'
  427. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) >= 21 AND (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) <= 50 THEN '21-50件'
  428. WHEN (nvl(si2.NOVPolicy,0) + nvl(si2.NOIVPolicy,0)) > 50 THEN '50件以上'
  429. END FROM shanglifeecif.individual si2 WHERE si1.indid = si2.indid);
  430. --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为'有贷款',否则更新为'无贷款'
  431. --第一步 以AUDIT_LN_LIST.LNMONEY更新InsuranceArrangement.LoanMoney
  432. 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);
  433. --第二步 以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID)
  434. --SELECT sig.applicantid,sum(sig.loanmoney) loanmoney FROM shanglifeecif.insurancearrangement sig GROUP BY sig.applicantid
  435. 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);
  436. --Label27:todo:无来源,逻辑需要说明清楚。
  437. --lable_27 志广说只用判断有极短意外险不用判断仅有
  438. UPDATE shanglifeecif.Individual si1 SET si1.Label27 = (
  439. SELECT
  440. CASE
  441. WHEN temp.cnt >0 THEN
  442. '有极短意外险'
  443. END
  444. FROM
  445. (
  446. SELECT
  447. count(1) cnt,
  448. policy.customerno
  449. FROM
  450. policy_information policy
  451. where
  452. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  453. and
  454. policy.riskperiod='短期险'
  455. and
  456. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  457. GROUP BY
  458. policy.customerno
  459. ) temp
  460. WHERE
  461. temp.customerno = si1.scustid
  462. );
  463. --2233条记录
  464. --Label28:保留暂不实现
  465. --Label29:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表(CUSTOMERNO),POLICY_INFORMATION.APPFLAG='有效' and POLICY_INFORMATION.PAYINTV='趸缴',若有记录则更新Individual.NOSPInsurance和本标签为'有趸交保单'
  466. UPDATE shanglifeecif.Individual si1 SET si1.label29 =
  467. (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);
  468. UPDATE shanglifeecif.Individual si1 SET si1.NOSPInsurance =
  469. (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);
  470. --Label30:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.ISelf为NULL,若有记录且RELATIONTOAPPNT仅为'本人'则若无记录则更新Individual.ISelf为'仅本人投保',若有记录且RELATIONTOAPPNT不为'本人'则若无记录则更新Individual.ISelf为'本人未投保',否则更新Individual.ISelf为'本人已投保'
  471. --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);
  472. --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);
  473. 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);
  474. 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);
  475. --label31 以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Iparent为NULL,若有记录且RELATIONTOAPPNT仅为'父母'则若无记录则更新Individual.Iparent为'仅父母投保',若有记录且RELATIONTOAPPNT不为'父母'则若无记录则更新Individual.Iparent为'父母未投保',否则更新Individual.Iparent为'父母已投保'
  476. --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);
  477. --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);
  478. 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);
  479. 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);
  480. --Label32:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.IChildren为NULL,若有记录且RELATIONTOAPPNT仅为'子女'则若无记录则更新Individual.IChildren为'仅子女投保',若有记录且RELATIONTOAPPNT不为'子女'则若无记录则更新Individual.IChildren为'子女未投保',否则更新Individual.IChildren为'子女已投保'
  481. --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);
  482. --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);
  483. 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);
  484. 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);
  485. --Label33:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Imate为NULL,若有记录且RELATIONTOAPPNT仅为'配偶'则若无记录则更新Individual.Imate为'仅配偶投保',若有记录且RELATIONTOAPPNT不为'配偶'则若无记录则更新Individual.Imate为'配偶未投保',否则更新Individual.Imate为'配偶已投保'
  486. --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);
  487. --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);
  488. 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);
  489. 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);
  490. --Label34:保留暂不实现
  491. --Label35:保留暂不实现
  492. --Label36:保留暂不实现
  493. --Label37:保留暂不实现
  494. --Label38:保留暂不实现
  495. --Label39:保留暂不实现
  496. --Label40:保留暂不实现
  497. --Label41:保留暂不实现
  498. --Label42:保留暂不实现
  499. --Label43:todo:逻辑需要说明清楚(到上游源表和字段)。
  500. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  501. SELECT
  502. CASE
  503. WHEN temp.cnt >0 THEN
  504. '有1年期短险保单'
  505. END
  506. FROM
  507. (
  508. SELECT
  509. count(1) cnt,
  510. policy.customerno
  511. FROM
  512. policy_information policy
  513. where
  514. policy.SECURITY in('1年','6月','180天')
  515. and
  516. policy.riskperiod='短期险'
  517. and
  518. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  519. GROUP BY
  520. policy.customerno
  521. ) temp
  522. WHERE
  523. temp.customerno = si1.scustid
  524. );
  525. --Label44:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且APPFLAG<>'有效',若无记录则更新Individual.NOIVPolicy为0,否则更新NOIVPolicy为记录数。若NOIVPolicy>0,则更新Individual.Label44为'有失效保单',否则更新为'无失效保单'
  526. UPDATE shanglifeecif.Individual si1 SET si1.label44 = (SELECT CASE WHEN si2.noivpolicy>0 THEN '有失效保单' END FROM shanglifeecif.individual si2 WHERE si2.indid = si1.indid);
  527. --LABEL45:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表且riskperiod='长期险',若无记录则更新Individual.Label45为NULL,若有记录且paycount= payendyear则更新Individual.Label45为'有缴费期满长险保单',否则更新Individual.Label45为'无缴费期满长险保单'
  528. 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);
  529. --Label46:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label46为NULL,若有记录且paycount= payendyear则更新Individual.Label46为'有续期缴费的保单',否则更新Individual.Label46为'无有续期缴费的保单'
  530. 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);
  531. --Label47:todo:逻辑需要说明清楚(到上游源表和字段)。
  532. --Label48:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最早日期(PADate)更新Individual.FADate
  533. -- 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);
  534. 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);
  535. --Label49:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),取最近日期(PADate)更新Individual.LAPPDate,最后用当前日期减去Individual.LAPPDate更新Label49
  536. 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);
  537. UPDATE shanglifeecif.Individual si1 SET si1.Label49 = (SELECT '最后一次投保距今' || TRUNC(months_between(sysdate(), si2.LAPPDate)/12) || '天' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  538. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel
  539. --Label50:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentChannel更新Individual.LPChannel,并更新此标签为:'最近保单'+Individual.LPChannel
  540. 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);
  541. UPDATE shanglifeecif.Individual si1 SET si1.Label50 = (SELECT '最近保单' || si1.LPChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  542. --Label51:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的AgentOrg更新Individual.LPOrg,并更新此标签为:'最近'+Individual.LPOrg+'机构'
  543. 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);
  544. UPDATE shanglifeecif.Individual si1 SET si1.Label51 = (SELECT '最近' || si2.LPOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid) ;
  545. --Label52:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentChannel更新Individual.FAChannel
  546. 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);
  547. UPDATE shanglifeecif.Individual si1 SET si1.Label52 = (SELECT '首单' || si2.FAChannel FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  548. --Label53:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最早日期(PADate)的AgentOrg更新Individual.FAOrg
  549. 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);
  550. UPDATE shanglifeecif.Individual si1 SET si1.Label53 = (SELECT '首单' || si2.FAOrg || '机构' FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  551. --Label54:以个体ID(Individual.IndID)查询InsuranceArrangement表(Individual.IndID=InsuranceArrangement.ApplicantID),以最近日期(PADate)的PolicyState更新Individual.LPState
  552. 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);
  553. --Label55 :Label55:由于上游保全类型信息分散在AUDIT_EDORLIST.EDORNAME和edorinfo.edortype 中,同时edorinfo.edortype为code需要转为string(具体映射见下)。以上游客户号(Individual.SCustID)分别查询AUDIT_EDORLIST表和edorinfo表,取保全生效日期最近的记录的更新的保全类型更新Individual.LPOSType。todo:edorinfo.edortype为code,需要转为string,edorinfo中需要增加上游客户号,否则需要多一次关联,建议大数据平台处理完成。
  554. --AUDIT_EDORLIST表里没有上游客户号,UPDATE shanglifeecif.Individual si1 SET si1.LPOSType =(SELECT ae.edorname FROM shanghailifeecif.audit_edorlist ae )
  555. 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
  556. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  557. LEFT JOIN shanghailifeecif.audit_edorlist sae ON sae.contno = spi.contno)
  558. UNION
  559. ( SELECT si2.scustid,se.edortype,se.edorappdate edorvalidate FROM shanglifeecif.Individual si2
  560. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  561. LEFT JOIN shanghailifeecif.edorinfo se ON se.contno = spi.contno)) temp) tt WHERE tt.scustid = si1.scustid AND tt.rd = 1);
  562. --Label56:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询INSURANCEINFO表 and INSURANCEINFO.APPFLAG = '已退保',若有记录则更新此标签为'有退保保单'
  563. UPDATE shanglifeecif.Individual si1 SET si1.Label56 =
  564. (SELECT CASE WHEN temp.cunm > 0 THEN '有退保保单' END FROM
  565. (
  566. SELECT count(1) cunm,si2.scustid FROM shanglifeecif.Individual si2
  567. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  568. LEFT JOIN shanghailifeecif.INSURANCEINFO sio ON spi.CONTNO = sio.CONTNO
  569. WHERE sio.APPFLAG = '已退保' GROUP BY si2.scustid
  570. ) temp WHERE temp.scustid = si1.scustid);
  571. --Label57:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION.CONTNO,再根据CONTNO查询AUDIT_CLAIM_INSURANCE表,取AUDIT_CLAIM_INSURANCE.RGTDATE最近对应的AUDIT_CLAIM_INSURANCE.RISKTYPE更新此标签。todo:实际数据仅有寿险、意外险、健康险,取值是否正确?
  572. UPDATE shanglifeecif.Individual si1 SET si1.Label57 =
  573. (SELECT temp.RISKTYPE FROM (
  574. SELECT si2.scustid,saci.RISKTYPE,row_number()OVER(PARTITION BY si2.scustid ORDER BY saci.RGTDATE DESC) rd FROM shanglifeecif.Individual si2
  575. LEFT JOIN shanghailifeecif.policy_information spi ON si2.scustid = spi.customerno
  576. LEFT JOIN shanghailifeecif.audit_claim_insurance saci ON saci.CONTNO = spi.CONTNO
  577. ) temp WHERE si1.scustid = temp.scustid AND temp.rd = 1);
  578. --Label59 :以个体ID(Individual.IndID)查询InsuranceClaimThread表(Individual.IndID=InsuranceClaimThread.ApplicantID), 以最近日期(CNDate)的ClaimCaseStatus更新Individual.CNStatus
  579. 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);
  580. --Label60:保留暂不实现
  581. --Label61:todo:逻辑需要说明清楚(到上游源表和字段)。
  582. --Label62:保留暂不实现
  583. --Label63:todo:逻辑需要说明清楚(到上游源表和字段)。
  584. --Label64:todo:逻辑需要说明清楚(到上游源表和字段)。
  585. --Label65:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label65为NULL,若仅一条记录则更新Individual.Label65为'一单寿险客户'
  586. UPDATE shanglifeecif.Individual si1 SET si1.Label65 =
  587. (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);
  588. --Label66:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表,若无记录则更新Individual.Label66为NULL,若 paycount= payendyear更新Individual.Label66为'缴费期满客户',否则更新为'非缴费期满客户
  589. UPDATE shanglifeecif.Individual si1 SET si1.Label66 =
  590. (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);
  591. --Label67:若Individual.Birthday的月日与上海人寿司庆日月日相同,则设置此标签为:'生日与司庆日同天'。todo:需要确定司庆日是几月几号
  592. 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);
  593. --Label68:以上游客户号(Individual.SCustID)查询POLICY_INFORMATION表, and POLICY_INFORMATION.APPFLAG='有效',若有记录则设置此标签为'持有有效保单',否则则设置为'未持有有效保单'
  594. UPDATE shanglifeecif.Individual si1 SET si1.Label68 = (SELECT CASE WHEN si2.NOVPolicy>0 THEN '持有有效保单' END FROM shanglifeecif.Individual si2 WHERE si1.indid = si2.indid);
  595. --Label69:Individual.CustClass,逻辑见上(一.7)
  596. UPDATE shanglifeecif.Individual si1 SET si1.Label69 = (SELECT si2.CustClass FROM shanglifeecif.Individual si2 WHERE si1.IndID = si2.IndID);
  597. --Label70:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Scenario更新此标签
  598. 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);
  599. --Label71:Individual.IndID = PartyTimeLine.PartyID,取PartyTimeLine.SDate最近的记录对应的Channel更新此标签
  600. 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);
  601. --Label72:保留暂不实现
  602. --Label73
  603. --Label74
  604. --Label75
  605. --Label76
  606. --Label77:Individual.Birthday 距离当前日期5天内,更新Individual.Label77为'本人生日临近',否则为NULL
  607. 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);
  608. --Label78:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'父亲'或'母亲'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label78为'父母生日临近',否则为NULL
  609. UPDATE shanglifeecif.Individual si1 SET si1.Label78 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '父母生日临近' END FROM (
  610. 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);
  611. --Label79:以个体ID(Individual.IndID)查询IndRelationShip表,若Role2为'儿子'或'女儿'的IndID2的生日(通过IndID2再反向关联Individual),则更新Individual.Label79为'子女生日临近',否则为NULL
  612. UPDATE shanglifeecif.Individual si1 SET si1.Label79 = (SELECT CASE WHEN DATEDIFF(sysdate(), si1.birthday)<=5 THEN '子女生日临近' END FROM (
  613. 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);
  614. --Label96:根据Individual.Birthday算出当前年龄,如果50<=年龄<60,则更新Individual.Label96为'大龄',否则为NULL
  615. 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);
  616. --Label97:根据Individual.Birthday算出当前年龄,如果60<=年龄,则更新Individual.Label97为'高龄',否则为NULL
  617. 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);
  618. --Label98:根据Individual.Occupation,若为记者、律师、公务员、媒体、金融行业,则更新Individual.Label98为'敏感职业',否则为NULL
  619. 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);
  620. --Label109:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='报案'且 InsuranceClaimThread.CNDate距当前日期超过7天,则更新Individual.Label109为'理赔报案追踪'
  621. 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);
  622. --Label110:以个体ID(Individual.IndID)查询InsuranceClaimThread,若ClaimCaseStatus='受理' or '立案',则更新Individual.Label110为'理赔处理中'
  623. 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 = '立案'));
  624. --Label112:先以个体ID(Individual.IndID)得到InsuranceArrangement.PolicyNo,再以此关联AUDIT_EDORLIST,若有记录且保全状态EDORSTATE<>'确认生效' and '复核终止' and '强制终止',则更新Individual.Label111为'保全处理中'
  625. 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);
  626. UPDATE shanglifeecif.Individual si1 SET si1.Label70 =
  627. (SELECT temp.scenario FROM (
  628. 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
  629. LEFT JOIN qxp.insurancearrangement qi ON qp.threadid = qi.policyno
  630. WHERE rd = 1
  631. ) temp WHERE temp.applicantid = si1.indid)
  632. --注册官微
  633. 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)
  634. --长通话逻辑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'
  635. UPDATE shanglifeecif.Individual si1 SET si1.label10 =
  636. (SELECT CASE WHEN tt.avgCallLenth>600 THEN '长通话' END FROM (
  637. SELECT temp.contnos,(temp.lenth/temp.callNum) as avgCallLenth,qi.applicantid FROM(
  638. 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
  639. GROUP BY m.contnos
  640. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.contnos = qi.policyno) tt WHERE tt.applicantid = si1.indid)
  641. --要求较多,每次来电均下转办单
  642. UPDATE shanglifeecif.Individual si1 SET si1.label103 =
  643. -- (SELECT '要求多' FROM shanghailifeecif.cc_swfflowmain swf
  644. -- LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  645. -- WHERE swf.flowid LIKE '%ZX%' AND si1.indid = qi.applicantid)
  646. (
  647. SELECT CASE WHEN t.callNum==t.swf_num THEN '要求较多' END FROM (
  648. SELECT count(*) AS callNum,srm.contnos,(SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  649. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  650. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  651. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  652. WHERE si1.indid = qi.applicantid
  653. )
  654. UPDATE shanglifeecif.Individual si1 SET si1.label104 =
  655. --(SELECT '易投诉升级' FROM shanghailifeecif.cc_swfflowmain swf
  656. --LEFT JOIN shanghailifeecif.cc_swf_sort scc ON scc.complaintProject = swf.id
  657. --LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  658. -- WHERE swf.flowid LIKE '%ZX%' AND scc.idname='投诉' AND si1.indid = qi.applicantid)
  659. (
  660. SELECT CASE WHEN t.callNum==t.swf_num THEN '易投诉升级' END FROM (
  661. SELECT count(*) AS callNum,srm.contnos,
  662. (SELECT count(*) FROM shanghailifeecif.cc_swfflowmain swf
  663. LEFT JOIN shanghailifeecif.cc_swf_sort scs ON swf.complaintproject = scs.id
  664. WHERE swf.flowid LIKE '%ZX%' AND srm.contnos = swf.policyno ) AS swf_num
  665. FROM shanghailifeecif.cc_record_main srm GROUP BY srm.contnos
  666. ) t LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = swf.policyno
  667. WHERE si1.indid = qi.applicantid
  668. )
  669. UPDATE shanglifeecif.Individual si1 SET si1.label105 =
  670. (SELECT '高频投诉' FROM (
  671. 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
  672. ) temp
  673. LEFT JOIN qxp.insurancearrangement qi ON qi.policyno = temp.productno
  674. WHERE temp.comnum >= 2 AND temp.dayNum <180 AND si1.indid = qi.applicantid
  675. )
  676. SELECT c.productno,c.inserttime FROM shanghailifeecif.cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  677. UPDATE shanglifeecif.Individual si1 SET si1.label106 =
  678. /*(SELECT CASE temp.complaintsSource when '914' then '重大投诉'
  679. when '919' then '重大投诉'
  680. when '915' then '重大投诉' END,qi.applicantid FROM (
  681. select c.complaintsSource,cd.productno from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd
  682. where cd.complaintsid=c.complaintsid
  683. ) temp LEFT JOIN qxp.insurancearrangement qi ON temp.productno = qi.policyno WHERE qi.applicantid = si1.indid)
  684. */
  685. (SELECT CASE WHEN tt.complaintsSource LIKE '%914%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%915%' THEN '重大投诉' WHEN tt.complaintsSource LIKE '%919%' THEN '重大投诉' END FROM (
  686. select group_concat(c.complaintsSource,',') AS complaintsSource,qi.applicantid from shanghailifeecif.cc_action_complaints c,shanghailifeecif.cc_action_data_complaints cd,qxp.insurancearrangement qi
  687. where cd.complaintsid=c.complaintsid AND qi.policyno = cd.productno
  688. GROUP BY qi.applicantid
  689. ) tt WHERE tt.applicantid = si1.indid)
  690. --lable_67 司庆日
  691. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = '司庆日' where birthday like '%-02-05';
  692. END ;