客户标签20210409预生产.sql 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.updateindividuallable() IS
  2. DECLARE
  3. BEGIN
  4. --1 学历 label1 按照客户最新记录中的学历取值 幼儿园、小学、中专、职高、技校、初中、高中、大专、本科、硕士及以上、其他
  5. UPDATE shanglifeecif.Individual si1 SET si1.label1 = si1.Education where si1.Education is not null;
  6. --2 职业 label2 按照客户最新记录中的职业名称取值 食用调料制作工、味精制作工、糕点、面包烘焙工、米面主食制作工、油脂制品工等
  7. UPDATE shanglifeecif.Individual si1 SET si1.label2 = si1.Occupation where si1.Occupation is not null;
  8. --3 出生日期区间 label3 根据出生日期,判断客户年代归属 60后、70后、80后、90后、00后、10后等
  9. UPDATE shanglifeecif.Individual si1 SET si1.label3 = substr(si1.birthday,3,1) || '0后' where 1 = 1;
  10. --4 年龄区间 label4 "case age when 0<=age and age<13 then '儿童' when 13<=age and age<19 then '少年' when 19<=age and age<41 then '青年' when 41<=age and age<66 then '中年' --else '老年'" 儿童、少年、青年、中年、老年
  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. --5 联系地址归属省份 label5 按照客户最近一次办理业务给出的最新联系地址取所在省名称或地级市的名称 省、直辖市:江苏、北京、上海等
  13. --6 联系地址归属地区 label6 按照客户最近一次办理业务给出的最新联系地址取所在市名称或者地级市所在区的名称 市:苏州市、南京市等
  14. --7 婚姻状况 label9 "根据婚姻状态字段判断 case maritalStat when maritalStat=1 then '未婚' when maritalStat=2 then '已婚' when maritalStat=3 then '丧偶' when maritalStat=4 --then '离异' else null" 1未婚、2已婚、3丧偶、4离异
  15. UPDATE shanglifeecif.Individual si1 SET si1.label9 = si1.maritalStat WHERE 1 = 1;
  16. --UPDATE shanglifeecif.Individual si1 SET si1.label9 = (
  17. --case si1.maritalStat
  18. --when 1 then '未婚'
  19. --when 2 then '已婚'
  20. --when 3 then '丧偶'
  21. --when 4 then '离异'
  22. --else NULL END
  23. --) WHERE 1 = 1;
  24. --8 子女数量区间 label10 "根据子女登录(登记录入)数量判断 case COChild when COChild=0 then '无子女' when COChild=1 then '1孩' when COChild>0 then '2孩及以上'
  25. --else null" 无子女、1孩、2孩及以上
  26. UPDATE shanglifeecif.individual si1 SET si1.cochild = (
  27. SELECT nvl(t.cnum,0) FROM (
  28. SELECT si.indid1,count(*) AS cnum FROM shanglifeecif.IndRelationShip si
  29. WHERE si.rstype = '子女' GROUP BY si.indid1
  30. ) t WHERE t.indid1 = si1.scustid
  31. ) ;
  32. UPDATE shanglifeecif.Individual si1 SET si1.label10 = (
  33. case
  34. when si1.COChild=0 then '无子女'
  35. when si1.COChild=1 then '1孩'
  36. when si1.COChild>=2 then '2孩及以上'
  37. else null END
  38. ) WHERE si1.cochild is not null;
  39. --9 最近5年是否曾或正在接受治疗 label11 按照该字段标识最后一次更新的结果判断,如果标识为true则显示“最近五年曾或正在接受治疗”,否则不做显示 近5年有治疗,近5年无治疗
  40. --10 是否饮酒 label12 按照该字段标识判断,只要记录中有一次标识为true,则显示“饮酒”,否则不做显示 饮酒
  41. --11 是否吸烟 label13 按照该字段标识判断,只要记录中有一次标识为true,则显示“吸烟”,否则不做显示 吸烟
  42. --12 是否有先天性疾病 label14 按照该字段标识最后一次更新的结果判断,如果标识为true则显示“有先天性疾病”,否则不做显示 有先天性疾病
  43. --13 是否患过重大疾病 label15 按照该字段标识最后一次更新的结果判断,如果标识为true则显示“患过重大疾病”,否则不做显示 患过重大疾病
  44. --14 家族是否有遗传病史 label16 按照该字段标识最后一次更新的结果判断,如果标识为true则显示“有遗传病”,否则不做显示 家族有遗传病史
  45. --15 是否正在怀孕 label17 按照该字段标识最后一次更新的结果判断,如果标识为true则显示“怀孕”,否则不做显示 正在怀孕
  46. --16 是否有早产、过期产、难产情况 label18 按照该字段标识判断,只要记录中有一次标识为true,则显示“有早产、过期产、难产情况”,否则不做显示 有早产、过期产、难产情况
  47. --17 是否进行危险性运动 label20 按照该字段标识判断,只要记录中有一次标识为true,则显示“进行危险性运动”,否则不做显示 进行危险性运动
  48. --18 个人年收入区间 label21 "根据个人年收入字段进行判断:case PIncome when PIncome<=120000 then '低收入' when PIncome>120000 and PIncome<=1000000 then '中产' when --PIncome>1000000 then '富人' else null" 低收入、中产、富人
  49. --根据数据判断单位应该是万元,这里都除以10000做判断
  50. UPDATE shanglifeecif.Individual si1 SET si1.Label21 = (
  51. CASE
  52. WHEN si1.pincome >=0 AND si1.pincome<=12 THEN '低收入'
  53. WHEN si1.pincome >12 AND si1.pincome<=100 THEN '中产'
  54. WHEN si1.pincome > 100 THEN '富人'
  55. else null END
  56. ) where 1 = 1;
  57. --19 拥有车辆数量区间 label22 "根据车辆登录数量字段进行判断:case COVehicle when COVehicle=0 then '无车' when COVehicle=1 then '1辆车' when COVehicle>1 then '2辆车以上'
  58. --else null" 无车,1辆车,2辆车及以上
  59. UPDATE shanglifeecif.Individual si1 SET si1.Label22 = (
  60. CASE
  61. WHEN si1.COVehicle ==0 THEN '无车'
  62. WHEN si1.COVehicle == 1 THEN '1辆车'
  63. WHEN si1.COVehicle > 1 THEN '2辆车以上'
  64. ELSE NULL END
  65. ) where 1 = 1;
  66. --20 拥有住房套数 label23 "根据房屋登录数量字段进行判断:case CORP when CORP=0 then '无房' when CORP=1 then '1套房' when CORP>1 then '2套房以上'
  67. --else null" 无房,1套房,2套房及以上
  68. UPDATE shanglifeecif.Individual si1 SET si1.Label23 = (
  69. CASE
  70. WHEN si1.CORP ==0 THEN '无房'
  71. WHEN si1.CORP == 1 THEN '1套房'
  72. WHEN si1.CORP > 1 THEN '2套房以上'
  73. else null END
  74. ) where 1 = 1;
  75. --21 是否持有寿险有效保单 label24 筛选客户名下所有保单,保单中客户为投保人,保单险种大类为寿险 持有寿险有效保单
  76. UPDATE shanglifeecif.Individual si1 SET si1.label24 = '持有寿险有效保单' WHERE si1.scustid in
  77. (SELECT p.customerno FROM dsj.policy_information p,dsj.riskkind l WHERE p.riskcode = l.riskcode AND p.appflag = '有效' AND (l.kindtype = '新型寿险' OR l.kindtype = '人寿保险'));
  78. --22 保单件数区间 label25 "判断客户作为投保人所有的保单数量(有效保单数量+失效保单数量):NOVPolicy+NOIVPolicy=pCount(保单总件数)
  79. --case pCount when pCount=1 then '1件' when pCount=2 then '2件' when pCount>2 and pCount<6 then '3-5件' when pCount>5 and pCount<11 then '6-10件'
  80. --when pCount>10 and pCount<21 then '10-20件'when pCount>20 and pCount<51 then '21-50件'
  81. --when pCount>50 then '50件以上' else '无保单'" 无保单、1件保单、2件保单、3-5件保单、6-10件保单、11-20件保单、20-50件保单、50件以上保单
  82. --第一步 更新 Individual.NOVPolicy 有效记录数
  83. --UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = (SELECT nvl(t.cnum,0) FROM (
  84. --SELECT temp.customerno,count(*) AS cnum FROM (
  85. --SELECT max(p.customerno) customerno,p.contno FROM dsj.policy_information p WHERE p.appflag = '有效' GROUP BY p.contno
  86. --) temp GROUP BY temp.customerno
  87. --) t WHERE t.customerno = si1.scustid);
  88. --第二步 更新 Individual.NOIVPolicy 无效记录数
  89. --UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = (SELECT nvl(t.cnum,0) FROM (
  90. --SELECT temp.customerno,count(*) AS cnum FROM (
  91. --SELECT max(p.customerno) customerno,p.contno FROM dsj.policy_information p WHERE p.appflag <> '有效' GROUP BY p.contno
  92. --) temp GROUP BY temp.customerno
  93. --) t WHERE t.customerno = si1.scustid);
  94. --第三步
  95. --UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  96. --CASE
  97. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  98. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件'
  99. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件'
  100. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件'
  101. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件'
  102. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件'
  103. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件'
  104. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件以上'
  105. --END ) where 1 = 1;
  106. --UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  107. --CASE
  108. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  109. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件保单'
  110. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件保单'
  111. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件保单'
  112. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件保单'
  113. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件保单'
  114. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件保单'
  115. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件保单以上'
  116. --END
  117. --) where 1 = 1;
  118. --23 是否贷款 label26 筛选客户为投保人的有效保单,且办理了贷款业务 有贷款
  119. UPDATE shanglifeecif.Individual si1 SET si1.label26 = '有保单贷款' WHERE si1.scustid IN (
  120. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (
  121. SELECT contno FROM dsj.loloandetail WHERE moneytype='DK'
  122. )
  123. );
  124. --24 是否有极短意保单/是否仅有极短意保单 label27 "客户为保单投保人 case AGRMNTAge(保险期限) when avg(sum(AGRMNTAges))<90 then '仅极短意外险'
  125. --when AGRMNTAge<90 then '有极短意外险'" 仅极短意外险,有极短意外险 志广说只用判断有极短意外险不用判断仅有
  126. /*UPDATE shanglifeecif.Individual si1 SET si1.Label27 = (
  127. SELECT
  128. CASE
  129. WHEN temp.cnt >0 THEN
  130. '有极短意外险'
  131. END
  132. FROM
  133. (
  134. SELECT
  135. count(1) cnt,
  136. policy.customerno
  137. FROM
  138. policy_information policy
  139. where
  140. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  141. and
  142. policy.riskperiod='短期险'
  143. and
  144. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  145. GROUP BY
  146. policy.customerno
  147. ) temp
  148. WHERE temp.customerno = si1.scustid
  149. );*/
  150. UPDATE shanglifeecif.Individual si1 SET si1.Label27 = (
  151. SELECT
  152. CASE
  153. WHEN temp.cnt > 0 AND temp.cnt = temp.tnum THEN '仅极短意外险'
  154. WHEN temp.cnt > 0 AND temp.cnt <> temp.tnum THEN '有极短意外险'
  155. END
  156. FROM (
  157. SELECT p.customerno,max(cnt) cnt,nvl(count(*),0) tnum FROM (
  158. SELECT
  159. count(1) cnt,
  160. policy.customerno
  161. FROM
  162. dsj.policy_information policy
  163. where
  164. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  165. and
  166. policy.riskperiod='短期险'
  167. and
  168. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  169. GROUP BY
  170. policy.customerno
  171. ) t LEFT JOIN dsj.policy_information p ON t.customerno = p.customerno GROUP BY p.customerno
  172. ) temp where temp.customerno = si1.scustid
  173. );
  174. --29 是否有趸交保单 Label29 有趸交保单 NOSPInsurance,POLICY_INFORMATION.PAYINTV='趸缴',PREMIUM_LIST.PAYMENT_PERIOD='一次交清'
  175. UPDATE shanglifeecif.Individual si1 SET si1.Label29 = '有趸交保单' WHERE si1.scustid IN (
  176. SELECT p.customerno FROM dsj.policy_information p WHERE p.payintv = '趸缴' and p.riskperiod = '长期险' AND p.contno IN (SELECT l.contno FROM dsj.PREMIUM_LIST l WHERE l.PAYMENT_PERIOD LIKE '%一次交清%')
  177. );
  178. --30 是否给本人投保 Label30 仅本人投保,本人已投保,本人未投保 Iself
  179. UPDATE shanglifeecif.Individual si1 SET si1.Label30 = (
  180. SELECT
  181. CASE
  182. WHEN tt.bnum = 0 THEN '本人未投保'
  183. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '为本人投保'
  184. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅为本人投保'
  185. END
  186. FROM (
  187. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  188. SELECT count(*) AS bnum,p.customerno FROM dsj.policy_information p WHERE p.relationtoappnt = '本人' GROUP BY p.customerno
  189. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  190. ) tt WHERE tt.customerno = si1.scustid
  191. );
  192. --32 是否给父母投保 Label31 仅父母投保,父母已投保,父母未投保 Iparent
  193. UPDATE shanglifeecif.Individual si1 SET si1.Label31 = (
  194. SELECT
  195. CASE
  196. WHEN tt.bnum = 0 THEN '父母未投保'
  197. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '为父母投保'
  198. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅为父母投保'
  199. END
  200. FROM (
  201. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  202. SELECT count(*) AS bnum,p.customerno FROM dsj.policy_information p WHERE (p.RELATIONTOAPPNT = '子女' OR p.RELATIONTOAPPNT = '父母') AND p.birthday > p.insuredbirthday
  203. GROUP BY p.customerno
  204. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  205. ) tt WHERE tt.customerno = si1.scustid
  206. );
  207. --34 是否给子女投保 Label32 仅子女投保,子女已投保,子女未·投保 Ichildren
  208. UPDATE shanglifeecif.Individual si1 SET si1.Label32 = (
  209. SELECT
  210. CASE
  211. WHEN tt.bnum = 0 THEN '子女未投保'
  212. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '为子女投保'
  213. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅为子女投保'
  214. END
  215. FROM (
  216. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  217. SELECT nvl(count(*),0) AS bnum,p.customerno FROM dsj.policy_information p WHERE (p.RELATIONTOAPPNT = '子女' OR p.RELATIONTOAPPNT = '父母') AND p.birthday < p.insuredbirthday GROUP BY p.customerno
  218. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  219. ) tt WHERE tt.customerno = si1.scustid
  220. );
  221. --36 是否给配偶投保 Label33 仅配偶投保,配偶已投保,配偶未投保 Imate
  222. UPDATE shanglifeecif.Individual si1 SET si1.Label33 = (
  223. SELECT
  224. CASE
  225. WHEN tt.bnum = 0 THEN '配偶未投保'
  226. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '为配偶投保'
  227. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅为配偶投保'
  228. END
  229. FROM (
  230. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  231. SELECT count(*) AS bnum,p.customerno FROM dsj.policy_information p WHERE p.relationtoappnt = '配偶' GROUP BY p.customerno
  232. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  233. ) tt WHERE tt.customerno = si1.scustid
  234. );
  235. --47 是否仅有1年期短险保单 Label43 仅有1年期短险保单,有1年期短险保单 "policy_information表 SECURITY in('1年','6月','180天') riskperiod=‘短期险’
  236. --riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')" 客户为保单投保人,所有保单的保障期限为一年
  237. /*UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  238. SELECT
  239. CASE
  240. WHEN temp.cnt >0 THEN
  241. '有1年期短险保单'
  242. END
  243. FROM
  244. (
  245. SELECT
  246. count(1) cnt,
  247. policy.customerno
  248. FROM
  249. policy_information policy
  250. where
  251. policy.SECURITY in('1年','6月','180天')
  252. and
  253. policy.riskperiod='短期险'
  254. and
  255. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  256. GROUP BY
  257. policy.customerno
  258. ) temp
  259. WHERE
  260. temp.customerno = si1.scustid
  261. );*/
  262. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  263. SELECT
  264. CASE
  265. WHEN temp.cnt > 0 AND temp.cnt = temp.tnum THEN '仅有1年期短险保单'
  266. WHEN temp.cnt > 0 AND temp.cnt <> temp.tnum THEN '有1年期短险保单'
  267. END
  268. FROM (
  269. SELECT p.customerno,max(cnt) cnt,nvl(count(*),0) tnum FROM (
  270. SELECT
  271. count(1) cnt,
  272. policy.customerno
  273. FROM
  274. dsj.policy_information policy
  275. where
  276. policy.SECURITY in('1年','6月','180天')
  277. and
  278. policy.riskperiod='短期险'
  279. and
  280. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  281. GROUP BY
  282. policy.customerno
  283. ) t LEFT JOIN dsj.policy_information p ON t.customerno = p.customerno GROUP BY p.customerno
  284. ) temp where temp.customerno = si1.scustid
  285. );
  286. --48 是否有失效保单 Label44 有失效保单 NOIVPolicy 客户为保单投保人,持有保单中保单状态为失效 (最新文档逻辑)
  287. UPDATE shanglifeecif.Individual si1 SET si1.label44 = '有失效保单' WHERE si1.scustid IN (
  288. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag <> '有效' and p.contno IN (select contno from dsj.lccontstate where statetype = 'Available' and state = '1')
  289. );
  290. --49 是否有缴费期满长险保单 Label45 有缴费期满长险保单 POLICY_INFORMATION:paycount= payendyear AND riskperiod='长期险' 客户持有保险期限为一年以上,剩余保费期数为0
  291. UPDATE shanglifeecif.Individual si1 SET si1.label45 = '有缴费期满长险保单' WHERE si1.scustid IN (
  292. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.paycount = p.payendyear AND p.riskperiod='长期险'
  293. );
  294. --50 是否有续期缴费的保单 Label46 有续期缴费的保单 客户为投保人,含有待缴费状态的保单
  295. UPDATE shanglifeecif.Individual si1 SET si1.label46 = '有续期缴费保单' WHERE si1.scustid IN (
  296. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (
  297. select otherno from dsj.ljspay where othernotype = '2'
  298. )
  299. );
  300. --51 有责任期满的保单 Label47 有责任期满的保单 客户持有保单含有保险期限已满的保单
  301. UPDATE shanglifeecif.Individual si1 SET si1.label47 = '有责任期满的保单' WHERE si1.scustid IN (
  302. SELECT p.customerno FROM dsj.policy_information p WHERE p.enddate < to_char(SYSDATE,"yyyy-MM-dd HH:mm:ss.S")
  303. );
  304. --52 第一张保单投保日期 Label48 首次投保日期XXXX-XX-XX FADate 客户所有保单中投保时间最早的日期
  305. --第一步
  306. UPDATE shanglifeecif.Individual si1 SET si1.FADate = (
  307. SELECT fadate FROM (
  308. SELECT p.customerno,min(p.polapplydate) AS fadate FROM dsj.POLICY_INFORMATION p WHERE p.polapplydate IS NOT null GROUP BY p.customerno
  309. ) t WHERE t.customerno = si1.scustid
  310. );
  311. UPDATE shanglifeecif.Individual si1 SET si1.FADate = (
  312. SELECT fadate FROM (
  313. SELECT p.insuredno,min(p.polapplydate) AS fadate FROM dsj.POLICY_INFORMATION p WHERE p.polapplydate IS NOT null GROUP BY p.insuredno
  314. ) t WHERE t.insuredno = si1.scustid
  315. );
  316. UPDATE shanglifeecif.Individual si1 SET si1.label48 = '首次投保日期'|| to_char(si1.fadate, 'yyyy-MM-dd') WHERE si1.fadate IS NOT NULL;
  317. --53 最后一次寿险投保距今时长 Label49 最后一次投保距今XXX天 LAPPDate 当前日期减去客户所有保单中最后一次投保的保单的投保时间
  318. UPDATE shanglifeecif.Individual si1 SET si1.LAPPDate = (
  319. SELECT fadate FROM (
  320. SELECT p.customerno,max(p.polapplydate) AS fadate FROM dsj.POLICY_INFORMATION p WHERE p.polapplydate IS NOT null GROUP BY p.customerno
  321. ) t WHERE t.customerno = si1.scustid
  322. );
  323. UPDATE shanglifeecif.Individual si1 SET si1.LAPPDate = (
  324. SELECT fadate FROM (
  325. SELECT p.insuredno,max(p.polapplydate) AS fadate FROM dsj.POLICY_INFORMATION p WHERE p.polapplydate IS NOT null GROUP BY p.insuredno
  326. ) t WHERE t.insuredno = si1.scustid
  327. );
  328. UPDATE shanglifeecif.Individual si1 SET si1.label49 = '最后一次投保距今' || DATEDIFF(sysdate(), si1.LAPPDate) || '天' WHERE si1.lappdate IS NOT NULL;
  329. --54 最近一次保单所属渠道 Label50 最近保单团险渠道、最近保单个人营销、最近保单银行代理、最近保单中介渠道、最近保单网销渠道 --LPChannel,InsuranceArrangement.AgentChannel 客户最后一次投保归属渠道
  330. UPDATE shanglifeecif.Individual si1 SET si1.label50 = (SELECT '最近保单' || trim(t.salecomname) FROM (
  331. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate DESC) rd,p.salecomname FROM dsj.POLICY_INFORMATION p
  332. WHERE p.salecomname IS NOT null
  333. ) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  334. --UPDATE shanglifeecif.Individual si1 SET si1.label50 = (SELECT t.SALECHNL FROM (
  335. --SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate DESC) rd,p.SALECHNL FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  336. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  337. --UPDATE shanglifeecif.Individual si1 SET si1.label50 = '最近保单' || si1.label50 WHERE si1.label50 IS NOT NULL;
  338. --55 最近一次保单所属机构 Label51 最近XX机构 LPOrg,InsuranceArrangement.AgentOrg 客户最后一次投保归属机构
  339. --UPDATE shanglifeecif.Individual si1 SET si1.label51 = (SELECT t.AGENTCOM FROM (
  340. -- SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate DESC) rd,p.AGENTCOM FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  341. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  342. --UPDATE shanglifeecif.Individual si1 SET si1.label51 = '最近机构' || si1.label51 WHERE si1.label51 IS NOT NULL;
  343. --56 最早保单所属渠道 Label52 首单团险渠道、首单个人营销、首单银行代理、首单中介渠道、首单网销渠道 FAChannel 客户第一次投保时保单归属渠道
  344. UPDATE shanglifeecif.Individual si1 SET si1.label52 = (SELECT '首单' || trim(t.salecomname) FROM (
  345. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate asc) rd,p.salecomname FROM dsj.POLICY_INFORMATION p WHERE p.salecomname IS NOT null
  346. ) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  347. --UPDATE shanglifeecif.Individual si1 SET si1.label52 = (SELECT t.SALECHNL FROM (
  348. --SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate asc) rd,p.SALECHNL FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  349. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  350. --UPDATE shanglifeecif.Individual si1 SET si1.label52 = '首单' || si1.label52 WHERE si1.label52 IS NOT NULL;
  351. --57 最早保单所属机构 Label53 首单XX机构 FAOrg 客户第一次投保时保单归属机构
  352. --UPDATE shanglifeecif.Individual si1 SET si1.label53 = (SELECT t.AGENTCOM FROM (
  353. -- SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate ASC) rd,p.AGENTCOM FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  354. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  355. --UPDATE shanglifeecif.Individual si1 SET si1.Label53 = '最近机构' || si1.Label53 WHERE si1.Label53 IS NOT NULL;
  356. --58 最近保单状态 Label54 "未承保承保新增附加险终止续保未对账对账失败" LPState 客户最后一张保单的保单状态
  357. /*
  358. UPDATE shanglifeecif.Individual si1 SET si1.label54 =
  359. (SELECT
  360. (CASE temp.appflag
  361. WHEN '0' THEN '最近保单状态未承保'
  362. WHEN '1' THEN '最近保单状态承保'
  363. WHEN '2' THEN '最近保单状态新增附加险'
  364. WHEN '4' THEN '最近保单状态终止'
  365. WHEN '9' THEN '最近保单状态续保'
  366. WHEN 'B' THEN '最近保单状态未对账'
  367. WHEN 'F' THEN '最近保单状态对账失败'
  368. END) a
  369. FROM (
  370. SELECT t.appflag,p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate desc) rd FROM dsj.policy_information p,dsj.lccont t WHERE p.contno = t.contno
  371. ) temp WHERE temp.rd = 1 AND si1.scustid = temp.customerno);
  372. */
  373. UPDATE shanglifeecif.Individual si1 SET si1.label54 = (
  374. SELECT '最近保单状态'||trim(t.appflag) FROM (
  375. SELECT row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate DESC) rd,p.customerno,p.appflag FROM dsj.policy_information p
  376. ) t WHERE t.rd = 1 AND si1.scustid = t.customerno
  377. );
  378. -- 最近一次保全类型 label55 客户最后一次办理保全业务的业务类型
  379. UPDATE shanglifeecif.Individual si1 SET si1.label55 = (
  380. SELECT '客户最近一次办理'||t.edorname FROM (
  381. SELECT
  382. row_number() over(partition by p.customerno ORDER BY l.edorAPPDATE DESC,l.uwtime DESC) rn,
  383. l.edortype,
  384. l.contno,
  385. p.customerno,
  386. l.edorappdate,
  387. l.edorstate,
  388. lm.edorcode,
  389. lm.edorname
  390. FROM dsj.lpedoritem l,dsj.lmedoritem lm,dsj.policy_information p
  391. WHERE l.edortype = lm.edorcode AND lm.appobj <> 'G' AND l.edorstate = '0' AND p.contno = l.contno
  392. ) t WHERE t.rn = 1 AND si1.scustid = t.customerno
  393. ) WHERE 1 = 1;
  394. --60 是否有退保保单 Label56 有退保保单 如何判断? 客户所有的保单中是否存在保单状态为退保的保单
  395. UPDATE shanglifeecif.Individual si1 SET si1.label56 = '有退保保单' WHERE si1.scustid IN (
  396. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  397. select contno from dsj.lpedoritem where edortype in ('CT', 'XT', 'GT') and edorstate = '0'
  398. )
  399. );
  400. --61 最近一次理赔类型 Label57 --意外医疗、意外伤残、意外死亡、意外高残、意外大病、意外特种疾病、意外失业失能、意外生命末期重疾、意外豁免、疾病医疗、疾病伤残、疾病死亡、疾病高残、疾病大病、疾病特种疾病、疾病失---业失能、疾病生命末期重疾、疾病豁免 无 客户最后一次投办理理赔业务的业务类型
  401. UPDATE shanglifeecif.Individual si1 SET si1.Label57 = (
  402. SELECT "最近一次理赔类型" || t.ACCIDENTTYPE FROM (
  403. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.ACCIDENTTYPE FROM dsj.INSURANCE_CLAIM c
  404. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  405. );
  406. --62 最近一次出险类型 Label58 疾病出险、意外出险 无 客户最后一次出险的类型
  407. UPDATE shanglifeecif.Individual si1 SET si1.Label58 = (
  408. SELECT "最近一次出险类型" || t.RISKTYPE FROM (
  409. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.RISKTYPE FROM dsj.INSURANCE_CLAIM c
  410. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  411. );
  412. --63 最近一次理赔状态 Label59 理赔报案中、理赔已受理、理赔已立案、理赔审核中、理赔预付审批中、理赔结案、理赔完成、理赔关闭 InsuranceClaimThread.ClaimCaseStatus --客户最后一次发生理赔的理赔类型
  413. UPDATE shanglifeecif.Individual si1 SET si1.Label59 = (
  414. SELECT '最近一次理赔状态' || t.LLCLAIMSTATE FROM (
  415. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.LLCLAIMSTATE FROM dsj.INSURANCE_CLAIM c
  416. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  417. );
  418. --65 是否有满期给付保单 Label61 有满期给付保单 如何判断? 0
  419. --select getdutycode from lmdutygetalive where getdutyname in ('满期保险金','满期生存保险金');
  420. UPDATE shanglifeecif.Individual si1 SET si1.label61 = '有满期给付保单' WHERE si1.scustid IN (
  421. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  422. SELECT contno FROM dsj.lcget WHERE getdutycode IN (select getdutycode from dsj.lmdutygetalive where getdutyname in ('满期保险金','满期生存保险金'))
  423. )
  424. );
  425. --67 是否有生存金给付的保单 Label63 有生存金给付保单 无 0
  426. --select getdutycode from lmdutygetalive where getdutyname = '生存保险金';
  427. UPDATE shanglifeecif.Individual si1 SET si1.label62 = '有生存金给付的保单' WHERE si1.scustid IN (
  428. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  429. SELECT contno FROM dsj.lcget WHERE getdutycode IN (select getdutycode from dsj.lmdutygetalive where getdutyname = '生存保险金')
  430. ) and p.appflag = '有效'
  431. );
  432. --68 是否有红利可领取的保单 Label64 有红利可领取保单 无 0
  433. UPDATE shanglifeecif.Individual si1 SET si1.label64 = '红利可领取的保单' WHERE si1.scustid IN
  434. (SELECT p.customerno FROM dsj.policy_information p,dsj.lmriskapp l WHERE p.appflag = '有效' and p.riskcode = l.riskcode AND l.bonusflag = 1);
  435. --69 一单寿险客户 Label65 一单寿险客户 客户仅购买了一张保单,且保单类型为寿险型保单
  436. UPDATE shanglifeecif.Individual si1 SET si1.label65 = '一单寿险客户' WHERE si1.scustid IN (SELECT temp.customerno FROM (
  437. SELECT pi.customerno,count(DISTINCT pi.contno) AS tnum,max(t.pnum) AS pnum FROM (
  438. SELECT count(DISTINCT p.contno) AS pnum,p.customerno FROM dsj.POLICY_INFORMATION p
  439. LEFT JOIN dsj.riskkind b on p.riskcode = b.riskcode
  440. WHERE (b.kindtype = '新型寿险' or b.kindtype = '人寿保险') GROUP BY p.customerno
  441. ) t LEFT JOIN dsj.POLICY_INFORMATION pi ON pi.customerno = t.customerno
  442. GROUP BY pi.customerno
  443. )temp WHERE temp.tnum = temp.pnum AND tnum = 1);
  444. --70 缴费期满客户 Label66 缴费期满客户 POLICY_INFORMATION:paycount= payendyear 客户缴费期数已满
  445. UPDATE shanglifeecif.Individual si1 SET si1.label66 = '缴费期满客户' WHERE si1.scustid IN (
  446. SELECT temp.customerno FROM (
  447. SELECT count(*) AS tnum,max(t.customerno) AS customerno,max(t.pnum) AS pnum FROM (
  448. SELECT p.customerno,count(*) AS pnum FROM dsj.policy_information p WHERE p.paycount = p.payendyear GROUP BY p.customerno
  449. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno
  450. GROUP BY pi.customerno
  451. ) temp WHERE temp.tnum = temp.pnum
  452. );
  453. --71 生日与司庆日同一天客户 Label67 生日与司庆日同天 2月15号 为司庆日 客户生日和公司司庆日为同一天
  454. UPDATE shanglifeecif.Individual si1 SET si1.Label67 = '生日与司庆日同天' where si1.birthday like '%-02-15%';
  455. --72 持有有效保单产品类型客户标签 Label68 持有有效保单,未持有有效保单 客户名下是否有投保人为自己的有效保单
  456. UPDATE shanglifeecif.Individual si1 SET si1.label68 = '持有有效保单' WHERE si1.scustid IN (SELECT t.customerno FROM (
  457. SELECT count(*) AS pnum,p.customerno FROM dsj.POLICY_INFORMATION p
  458. WHERE p.appflag = '有效' GROUP BY p.customerno
  459. ) t WHERE t.pnum > 0);
  460. --73 客户等级标签 Label69 钻石、白金、黄金、普通 Individual.CustClass 根据CustClass字段已有的等级值显示
  461. --UPDATE shanglifeecif.Individual si1 SET si1.Label69 = si1.CustClass where 1 = 1;
  462. UPDATE shanglifeecif.Individual si1 SET si1.Label69 = (
  463. CASE si1.CustClass
  464. WHEN 1 THEN '钻石客户'
  465. WHEN 2 THEN '白金客户'
  466. WHEN 3 THEN '黄金客户'
  467. --WHEN 4 THEN '普通级别'
  468. --ELSE '无级别'
  469. ELSE ''
  470. END
  471. ) where 1 = 1;
  472. --74 最近接触业务类型 Label70 最近投诉、最近问询(咨询)、最近营销、最近理赔、最近出险、最近保全 Individual.LCType 客户最后一次接触的业务类型
  473. UPDATE shanglifeecif.Individual si1 SET si1.Label70 = (
  474. SELECT '最近'||t.scenario FROM (
  475. SELECT
  476. row_number()OVER(PARTITION BY pl.partyid ORDER BY pl.sdate desc) rn,
  477. pl.partyid,
  478. pl.scenario
  479. FROM shanglifeecif.partytimeline pl WHERE pl.partyid IS NOT NULL
  480. ) t WHERE t.rn = 1 AND si1.scustid = t.partyid
  481. );
  482. --75 最近接触方式 Label71 最近外呼、最近呼入、微信 Individual.LCMethod 客户最后一次接触的方式
  483. UPDATE shanglifeecif.Individual si1 SET si1.Label71 = (
  484. SELECT '最近'||CASE t.scenario WHEN '回访' THEN '外呼' WHEN '咨询' THEN '呼入' END FROM (
  485. SELECT
  486. row_number()OVER(PARTITION BY pl.partyid ORDER BY pl.sdate desc) rn,
  487. pl.partyid,
  488. pl.scenario
  489. FROM shanglifeecif.partytimeline pl WHERE pl.partyid IS NOT NULL AND (pl.scenario = '回访' OR pl.scenario = '咨询')
  490. ) t WHERE t.rn = 1 AND si1.scustid = t.partyid
  491. );
  492. --77 是否关注官微 Label73 关注官微 无 0
  493. --UPDATE shanglifeecif.Individual si1 SET si1.Label73 = '关注官微'
  494. --WHERE si1.idcard IN (SELECT a.certificate_no FROM account a)
  495. --OR si1.passport IN (SELECT a.certificate_no FROM account a)
  496. --OR si1.Dlicense IN (SELECT a.certificate_no FROM account a)
  497. --OR si1.othernumber IN (SELECT a.certificate_no FROM account a);
  498. --78 是否注册官微 Label74 注册官微 无 0
  499. UPDATE shanglifeecif.Individual si1 SET si1.Label74 = '注册官微'
  500. WHERE si1.idcard IN (SELECT a.certificate_no FROM dsj.account a WHERE a.account_status = 0)
  501. OR si1.passport IN (SELECT a.certificate_no FROM dsj.account a WHERE a.account_status = 0)
  502. OR si1.Dlicense IN (SELECT a.certificate_no FROM dsj.account a WHERE a.account_status = 0)
  503. OR si1.othernumber IN (SELECT a.certificate_no FROM dsj.account a WHERE a.account_status = 0);
  504. -- 本人生日提醒 Label77 本人生日临近 客户生日-当前日期<5
  505. --UPDATE shanglifeecif.Individual si1 SET si1.label77 = '本人生日临近' WHERE DATEDIFF(to_char(SYSDATE,"2021-MM-dd"),to_char(si1.birthday,"2021-MM-dd"))<=5 AND
  506. --DATEDIFF(to_char(SYSDATE,"2021-MM-dd"),to_char(si1.birthday,"2021-MM-dd"))>0;
  507. UPDATE shanglifeecif.Individual si1 SET si1.label77 = '本人生日临近' WHERE DATEDIFF(to_char(si1.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))<=5 AND
  508. DATEDIFF(to_char(si1.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))>0;
  509. UPDATE shanglifeecif.Individual si1 SET si1.label78 = '父母生日临近' WHERE si1.scustid IN (
  510. SELECT sis.indid1 FROM shanglifeecif.indrelationship sis LEFT JOIN shanglifeecif.individual si ON sis.indid2 = si.scustid
  511. WHERE sis.rstype = '父母' AND DATEDIFF(to_char(si.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))<=5 AND
  512. DATEDIFF(to_char(si.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))>0
  513. );
  514. UPDATE shanglifeecif.Individual si1 SET si1.label79 = '子女生日临近' WHERE si1.scustid IN (
  515. SELECT sis.indid1 FROM shanglifeecif.indrelationship sis LEFT JOIN shanglifeecif.individual si ON sis.indid2 = si.scustid
  516. WHERE sis.rstype = '子女' AND DATEDIFF(to_char(si.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))<=5 AND
  517. DATEDIFF(to_char(si.birthday,"2021-MM-dd"),to_char(SYSDATE,"2021-MM-dd"))>0
  518. );
  519. --69 近期咨询过产品 label80 7天内呼入咨询过,呼叫中心服务记录、咨询转办单提取关键字段(包含产品咨询)或服务记录中包含保单基本信息、投保咨询 近期咨询产品
  520. UPDATE shanglifeecif.Individual si1 SET si1.Label80 = '近期咨询过产品' WHERE si1.scustid IN (
  521. SELECT dp.customerno FROM dsj.policy_information dp WHERE dp.contno IN (
  522. SELECT rm.contnos FROM dsj.cc_record_main rm WHERE (rm.reasonsecondname LIKE '%保单基本信息%' OR rm.reasonsecondname LIKE '%投保咨询%')
  523. and rm.contnos IS not NULL AND DATEDIFF(SYSDATE,rm.starttime) < 7 )
  524. );
  525. --70 近期咨询过理赔 label81 7天内呼入咨询过,呼叫中心服务记录、咨询转办单提取关键字段(包含理赔咨询)或服务记录、咨询转办单中包含理赔字段 近期咨询理赔
  526. UPDATE shanglifeecif.Individual si1 SET si1.Label81 = '近期咨询过理赔' WHERE si1.scustid IN (
  527. SELECT dp.customerno FROM dsj.policy_information dp WHERE dp.contno IN (
  528. SELECT rm.contnos FROM dsj.cc_record_main rm WHERE rm.reasonsecondname LIKE '%理赔%'
  529. and rm.contnos IS not NULL AND DATEDIFF(SYSDATE,rm.starttime) < 7)
  530. );
  531. --75 续期临期未缴费 label88 续期缴费期到宽限期未交费,续期缴费日期-当前日期<5 续期临期未缴费
  532. UPDATE shanglifeecif.Individual si1 SET si1.Label88 = '续期临期未缴费' WHERE si1.scustid IN (
  533. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效'AND p.payintv = '期缴' AND p.payendyear<>p.paycount AND
  534. DATEDIFF(p.paytodate,to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S')) > 0 and DATEDIFF(p.paytodate,to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S')) < 5
  535. );
  536. --76 续期到期未缴费 label89 过了续期宽限期,仍未缴费 续期到期未缴费
  537. UPDATE shanglifeecif.Individual si1 SET si1.Label89 = '续期到期未缴费' WHERE si1.scustid IN (
  538. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效'AND p.payintv = '期缴' AND p.payendyear<>p.paycount AND
  539. to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S') > DATE_ADD(p.paytodate, 60)
  540. );
  541. --93 失效客户 Label91 失效客户 所有保单都是失效状态 客户名下所有保单均失效的客户
  542. UPDATE shanglifeecif.Individual si1 SET si1.Label91 = '失效客户' WHERE si1.scustid IN (SELECT temp.customerno FROM (
  543. SELECT count(*) AS tnum,max(t.customerno) AS customerno,max(t.pnum) AS pnum FROM (
  544. SELECT p.customerno,count(*) AS pnum FROM dsj.policy_information p WHERE p.appflag <> '有效' GROUP BY p.customerno
  545. ) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno
  546. GROUP BY pi.customerno
  547. ) temp WHERE temp.tnum = temp.pnum);
  548. --失效原因
  549. UPDATE shanglifeecif.Individual si1 SET si1.label92 = (
  550. SELECT '有'||t.terminatestate||'保单' FROM (
  551. SELECT row_number()over(partition by p.customerno order by p.polapplydate desc) rn,p.customerno,p.terminatestate FROM dsj.policy_information p
  552. WHERE p.appflag = '失效'
  553. ) t WHERE t.rn = 1 AND si1.scustid = t.customerno
  554. );
  555. -- 终止客户 label93 客户的所有保单缴费期满且承保期限已满正常终止的客户 终止客户
  556. --UPDATE shanglifeecif.Individual si1 SET si1.Label93 = '终止客户' WHERE si1.scustid IN (SELECT temp.customerno FROM (
  557. --SELECT count(*) AS tnum,max(t.customerno) AS customerno,max(t.pnum) AS pnum FROM (
  558. --SELECT p.customerno,count(*) AS pnum FROM dsj.policy_information p WHERE p.appflag = '终止' AND p.enddate < to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S') GROUP BY p.customerno
  559. --) t LEFT JOIN dsj.policy_information pi ON pi.customerno = t.customerno
  560. --GROUP BY pi.customerno
  561. --) temp WHERE temp.tnum = temp.pnum);
  562. --终止原因
  563. UPDATE shanglifeecif.Individual si1 SET si1.Label94 = (
  564. SELECT '有'||t.terminatestate||'保单' FROM (
  565. SELECT row_number()over(partition by p.customerno order by p.polapplydate desc) rn,p.customerno,p.terminatestate FROM dsj.policy_information p
  566. WHERE p.appflag = '终止'
  567. ) t WHERE t.rn = 1 AND si1.scustid = t.customerno
  568. );
  569. --81 上年续期交费情况 label95 相对于上一年的交费日期和实收日期,提前X天交费、滞后X天交费、宽限期外交费、失效客户 提前X天交费、滞后X天交费、宽限期外交费
  570. --UPDATE shanglifeecif.Individual si1 SET si1.Label95 = (
  571. --SELECT
  572. --CASE
  573. -- WHEN temp.dnum<0 THEN '上一年提前'||abs(temp.dnum)||'天交费'
  574. -- WHEN temp.dnum>0 THEN '上一年滞后'||temp.dnum||'天交费'
  575. -- WHEN temp.toconfdate > temp.kxdate THEN '上一年宽限期外交费'
  576. --END
  577. -- FROM (
  578. -- SELECT row_number()over(PARTITION BY t.appntno ORDER BY t.confdate DESC) rn,t.appntno,t.paydate as topaydate,t.confdate as toconfdate,DATE_ADD(t.paydate,60) as --kxdate,tt.paydate as lastpaydate,tt.confdate AS lastconfdate,DATEDIFF(to_char(t.confdate,'0000-MM-dd'),to_char(tt.confdate,'0000-MM-dd')) AS dnum FROM (
  579. -- SELECT row_number()OVER(PARTITION BY ln.contno ORDER BY ln.paydate DESC) rd,ln.* FROM dsj.ljapayperson ln
  580. -- WHERE ln.confdate IS NOT NULL AND ln.paydate IS NOT null
  581. -- ) t LEFT JOIN (
  582. -- SELECT row_number()OVER(PARTITION BY ln2.contno ORDER BY ln2.paydate DESC) rd,ln2.* FROM dsj.ljapayperson ln2
  583. -- WHERE ln2.confdate IS NOT NULL AND ln2.paydate IS NOT null AND ln2.paycount > 1
  584. -- ) tt ON t.contno = tt.contno AND t.rd = tt.rd - 1 WHERE t.rd = 1 AND tt.rd = 2
  585. -- ) temp WHERE temp.dnum <> 0 AND temp.rn = 1 AND si1.scustid = temp.appntno
  586. --) WHERE 1 = 1;
  587. --UPDATE shanglifeecif.Individual si1 SET si1.Label95 = (
  588. -- SELECT
  589. -- CASE
  590. -- WHEN t.dnum<0 THEN '提前'||abs(t.dnum)||'天交费'
  591. -- WHEN t.dnum>0 AND t.dnum<=60 THEN '滞后'||t.dnum||'天交费'
  592. -- WHEN t.dnum>60 THEN '宽限期外交费'
  593. -- END
  594. -- FROM (
  595. -- SELECT row_number()over(PARTITION BY p.customerno ORDER BY p.confdate DESC) rn,p.customerno,DATEDIFF(to_char(p.confdate,'0000-MM-dd'),to_char(p.polapplydate,'0000-MM-dd')) AS dnum FROM dsj.policy_information p
  596. -- WHERE p.appflag = '有效' AND p.payintv = '期缴'
  597. -- ) t WHERE t.dnum <> 0 AND t.rn = 1 AND si1.scustid = t.customerno
  598. --) WHERE 1 = 1;
  599. UPDATE shanglifeecif.Individual si1 SET si1.Label95 = (
  600. SELECT
  601. CASE
  602. WHEN t.dnum=0 THEN '上一年如期缴费'
  603. WHEN t.dnum<0 THEN '上一年提前'||abs(t.dnum)||'天交费'
  604. WHEN t.dnum>0 AND t.dnum<=60 THEN '上一年滞后'||t.dnum||'天交费'
  605. WHEN t.dnum>60 THEN '上一年宽限期外交费'
  606. END
  607. FROM (
  608. SELECT
  609. row_number()over(PARTITION BY l.appntno ORDER BY l.confdate DESC) rn,l.appntno,DATEDIFF(to_char(l.confdate,'0000-MM-dd'),to_char(l.curpaytodate,'0000-MM-dd')) AS dnum
  610. FROM dsj.ljapayperson l WHERE l.paycount > 1 AND YEAR(l.confdate) = YEAR(sysdate) - 1
  611. ) t WHERE t.rn = 1 AND t.appntno = si1.scustid
  612. ) WHERE 1 = 1;
  613. --98 大龄 Label96 大龄 来电客户年龄50岁以上
  614. UPDATE shanglifeecif.Individual si1 SET si1.Label96 = '大龄' where si1.scustid IN (
  615. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  616. SELECT contnos from dsj.cc_record_main
  617. )
  618. ) AND TRUNC(months_between(sysdate, si1.birthday)/12)>=50 AND TRUNC(months_between(sysdate, si1.birthday)/12)<60;
  619. --99 高龄 Label97 高龄 来电客户年龄60岁以上
  620. UPDATE shanglifeecif.Individual si1 SET si1.Label97 = '高龄' where si1.scustid IN (
  621. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  622. SELECT contnos from dsj.cc_record_main
  623. )
  624. ) AND TRUNC(months_between(sysdate, si1.birthday)/12)>=60;
  625. --100 敏感职业 Label100 敏感职业 投保人职业为记者、律师、公务员、媒体、金融行业
  626. UPDATE shanglifeecif.Individual si1 SET si1.Label100 = (CASE WHEN si1.occupation like '%记者%' OR si1.occupation like '%律师%' OR si1.occupation like '%公务员%' OR si1.occupation like '%媒体%' OR si1.occupation like '%金融行业%' THEN '敏感职业' END ) WHERE 1 = 1;
  627. --102 公司销售人员 Label100 公司销售人员 姓名与保单经办人一致 客户为公司销售人员
  628. --103 长通话 Label101 长通话 "contnos为客户的保单号 select (select lo.call_length from ucc_rms_recorderlog lo where lo.call_id=m.call_id) as lenth from cc_record_main m
  629. --where m.contnos='2019082000110188'" 平均通话时长超过10分钟
  630. UPDATE shanglifeecif.Individual si1 SET si1.Label101 = (
  631. SELECT '长通话' FROM (
  632. SELECT
  633. t.contnos,
  634. row_number()OVER(PARTITION BY p.customerno) rn,
  635. p.customerno
  636. FROM (
  637. SELECT (sum(lo.call_length)/count(*)) AS avgcalltime,m.contnos from dsj.cc_record_main m
  638. LEFT JOIN dsj.ucc_rms_recorderlog lo ON m.call_id = lo.call_id
  639. WHERE m.contnos IS NOT NULL AND lo.call_length IS NOT NULL
  640. GROUP BY m.contnos
  641. ) t LEFT JOIN dsj.policy_information p ON t.contnos = p.contno
  642. WHERE t.avgcalltime>600
  643. ) temp WHERE temp.customerno IS NOT NULL AND temp.rn = 1 AND si1.scustid = temp.customerno
  644. );
  645. --105 要求较多 Label103 要求较多 "policyno为客户的保单号 flowid like'ZX%'转办标志 Z select (select r.idname from cc_swf_sort r where r.id=f.complaintProject) as --swfName --from cc_swfflowmain f where f.policyno='2020021500000456' and flowid like'ZX%'" 每次来电均下转办单的
  646. UPDATE shanglifeecif.Individual si1 SET si1.Label103 = '要求较多' WHERE si1.scustid IN (
  647. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  648. SELECT temp.policyno FROM (
  649. SELECT t.policyno,max(t.mnum) mnum,max(t.fnum) fnum FROM (
  650. SELECT m.contnos policyno,count(*) AS mnum,'' AS fnum FROM dsj.cc_record_main m WHERE m.contnos IS NOT NULL GROUP BY m.contnos
  651. UNION
  652. SELECT f.policyno,'' AS mnum,count(*) AS fnum FROM dsj.cc_swfflowmain f WHERE f.modelno = 1 GROUP BY f.policyno
  653. )t GROUP BY t.policyno
  654. ) temp WHERE (temp.fnum/temp.mnum)>0.7
  655. )
  656. );
  657. --106 易投诉升级 Label104 易投诉升级 "flowid like'ZX%'转办标志 Z select (select r.idname from cc_swf_sort r where r.id=f.complaintProject and r.idname='投诉') as swfName --from cc_swfflowmain f where f.policyno='2020021500000456' and flowid like'ZX%'" 咨询转办单项目为投诉
  658. UPDATE shanglifeecif.Individual si1 SET si1.Label104 = '易投诉升级' WHERE si1.scustid IN (
  659. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  660. SELECT temp.policyno FROM (
  661. SELECT t.policyno,max(t.mnum) mnum,max(t.fnum) fnum FROM (
  662. SELECT m.contnos policyno,count(*) AS mnum,'' AS fnum FROM dsj.cc_record_main m WHERE m.contnos IS NOT NULL GROUP BY m.contnos
  663. UNION
  664. SELECT f.policyno,'' AS mnum,count(*) AS fnum FROM dsj.cc_swfflowmain f,dsj.cc_swf_sort r WHERE r.id=f.complaintProject and f.modelno = 1 AND r.idname='投诉' GROUP BY f.policyno
  665. )t GROUP BY t.policyno
  666. ) temp WHERE temp.mnum = temp.fnum
  667. )
  668. );
  669. --107 高频投诉 Label105 高频投诉 "select count(1) from cc_action_data_complaints c where c.productno='2018110400035608'" --半年之内来过两次以上投诉的,投诉受理日期间隔<180天,且投诉次数>2
  670. --UPDATE shanglifeecif.Individual si1 SET si1.Label105 = '高频投诉' WHERE si1.scustid in
  671. --(SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN
  672. --(SELECT temp.productno FROM (
  673. --SELECT t.productno,t.sinserttime,
  674. --(SELECT tt.inserttime FROM (SELECT cad.inserttime,row_number()OVER(PARTITION BY cad.productno ORDER BY cad.inserttime) rownum,cad.productno FROM dsj.cc_action_complaints --ca,dsj.cc_action_data_complaints cad
  675. --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
  676. -- FROM
  677. --(
  678. -- select cd.productno,row_number()OVER(PARTITION BY cd.productno ORDER BY cd.inserttime) rn,cd.inserttime AS sinserttime
  679. -- from dsj.cc_action_complaints c,dsj.cc_action_data_complaints cd WHERE cd.complaintsid=c.complaintsid AND cd.productno IS NOT NULL
  680. --) t
  681. --) temp WHERE temp.esinserttime IS NOT NULL AND DATEDIFF(temp.esinserttime,temp.sinserttime) < 180));
  682. UPDATE shanglifeecif.Individual si1 SET si1.Label105 = '高频投诉' WHERE si1.scustid in (
  683. SELECT t.customerno FROM (
  684. SELECT
  685. row_number()OVER(PARTITION BY t1.customerno ORDER BY ca.inserttime) rownum,
  686. t1.customerno,
  687. t1.contno,
  688. ca.inserttime FROM (
  689. SELECT
  690. max(p.customerno) customerno,
  691. p.contno
  692. FROM dsj.policy_information p GROUP BY p.contno
  693. ) t1 LEFT JOIN dsj.cc_action_complaints ca ON t1.contno = ca.productnos
  694. ) t LEFT JOIN (
  695. SELECT
  696. row_number()OVER(PARTITION BY t1.customerno ORDER BY ca.inserttime) rownum,
  697. t1.customerno,
  698. t1.contno,
  699. ca.inserttime FROM (
  700. SELECT
  701. max(p.customerno) customerno,
  702. p.contno
  703. FROM dsj.policy_information p GROUP BY p.contno
  704. ) t1 LEFT JOIN dsj.cc_action_complaints ca ON t1.contno = ca.productnos
  705. ) tt ON t.customerno = tt.customerno AND t.rownum = tt.rownum+1
  706. WHERE DATEDIFF(tt.inserttime,t.inserttime) < 180
  707. );
  708. --SELECT c.productno,c.inserttime FROM cc_action_data_complaints c WHERE c.productno IS NOT NULL GROUP BY c.productno
  709. --108 重大投诉影响 Label106 重大投诉影响 投诉来源 投诉来源是保监局、保监会、媒体转办的
  710. UPDATE shanglifeecif.Individual si1 SET si1.Label106 = (
  711. SELECT
  712. CASE
  713. WHEN tt.complaintsSource LIKE '%保监会%' THEN '重大投诉'
  714. WHEN tt.complaintsSource LIKE '%保监局%' THEN '重大投诉'
  715. WHEN tt.complaintsSource LIKE '%媒体转办%' THEN '重大投诉' END FROM (
  716. SELECT pi.customerno,max(complaintsSource) AS complaintsSource FROM (
  717. select group_concat((case c.complaintsSource
  718. when '911' then '来电'
  719. when '912' then '来访'
  720. when '913' then '来函'
  721. when '914' then '保监会转办'
  722. when '919' then '保监局转办'
  723. when '915' then '媒体转办'
  724. when '916' then '同业公会'
  725. when '917' then '其他转办'
  726. when '918' then '呼出'
  727. else c.complaintsSource END),',') as complaintsSource,p.contno from dsj.cc_action_complaints c,dsj.cc_action_data_complaints cd,dsj.policy_information p
  728. where cd.complaintsid=c.complaintsid AND p.contno = cd.productno GROUP BY p.contno
  729. ) t LEFT JOIN dsj.policy_information pi ON t.contno = pi.contno GROUP BY pi.customerno
  730. ) tt WHERE tt.customerno = si1.scustid
  731. );
  732. --109 高金额 Label107 高金额 关于高金额的指标,鉴于大数据无法计算件均保费,调整逻辑如下:
  733. --根据业绩归属渠道、缴费方式、以及期缴保费划分如下
  734. --02个险渠道 期缴 大于20000以上
  735. --03银保渠道 期缴 大于50000以上
  736. --06健康险 期缴 大于 20000以上
  737. UPDATE shanglifeecif.Individual si1 SET si1.Label107 = '高金额'
  738. WHERE si1.scustid IN (SELECT p.customerno FROM dsj.policy_information p WHERE
  739. p.appflag = '有效' AND p.payintv = '期缴' and
  740. ((p.salecom = '03' AND p.prem>50000) OR (p.salecom = '02' AND p.prem>20000) OR (p.salecom = '06' AND p.prem>20000)));
  741. --最近理赔结案 label108 最近15天做过理赔,当前日期-理赔结案日期<15天 最近理赔结案
  742. UPDATE shanglifeecif.Individual si1 SET si1.Label108 = '最近理赔结案' WHERE si1.scustid IN (
  743. SELECT c.insuredno FROM dsj.INSURANCE_CLAIM c WHERE DATEDIFF(to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S'),c.endcasedate) < 15
  744. );
  745. --111 理赔报案追踪 Label109 理赔报案追踪 理赔状态为报案状态,且理赔报案日-当前日期<30天
  746. UPDATE shanglifeecif.Individual si1 SET si1.Label109 = '理赔报案追踪' WHERE si1.scustid IN (SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (SELECT c.CONTNO FROM dsj.insurance_claim c WHERE c.LLCLAIMSTATE = '报案' AND DATEDIFF(sysdate(), c.RPTDATE) <30) );
  747. --112 理赔处理中 Label110 理赔处理中 理赔状态为受理或立案
  748. UPDATE shanglifeecif.Individual si1 SET si1.label110 = '理赔处理中' WHERE si1.scustid IN (
  749. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (SELECT c.contno FROM dsj.INSURANCE_CLAIM c WHERE c.llclaimstate = '受理' OR c.llclaimstate = '立案')
  750. );
  751. --最近保全完成 label111 最近15天做过保全,来电日期-保全申请日期<15天 最近保全完成
  752. UPDATE shanglifeecif.Individual si1 SET si1.Label111 = '最近保全完成' WHERE si1.scustid IN (
  753. SELECT p.customerno FROM dsj.policy_information p WHERE p.contno IN (
  754. SELECT l.contno FROM dsj.lpedoritem l WHERE DATEDIFF(to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S'),l.edorappdate) < 15 AND l.edorstate = '0'
  755. )
  756. );
  757. --115 生存金未领 Label113 生存金未领 判断逻辑不详 生存金领取方式为自动转账、存在生存金且未领取
  758. UPDATE shanglifeecif.Individual si1 SET si1.label113 = '生存金未领' WHERE si1.scustid IN (
  759. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (
  760. SELECT contno FROM dsj.Lcinsureacc WHERE acctype = '005' and insuaccbala>0
  761. )
  762. );
  763. --117 红利垫缴还款 Label115 红利垫缴还款 判断逻辑不详 存在红利,且红利已经垫交保单还款
  764. UPDATE shanglifeecif.Individual si1 SET si1.label115 = '红利垫缴还款' WHERE si1.scustid IN (
  765. SELECT p.customerno FROM dsj.policy_information p WHERE p.appflag = '有效' and p.contno IN (
  766. SELECT a.contno FROM dsj.LOLOANDETAIL a,dsj.LDCode1 b WHERE
  767. b.codetype='lnmoneytype' AND b.code=a.finfeetype and b.code1=a.moneytype
  768. )
  769. );
  770. -- 宽限期 label117 宽限日末日-当前日期<3天 宽限期
  771. UPDATE shanglifeecif.Individual si1 SET si1.label117 = '宽限期' WHERE si1.scustid IN (
  772. SELECT p.customerno FROM dsj.policy_information p WHERE p.payintv= '期缴' AND p.appflag='有效' AND p.payendyear!=p.paycount and
  773. DATEDIFF(DATE_ADD(p.paytodate, 60),to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S')) > 0 AND DATEDIFF(DATE_ADD(p.paytodate, 60),to_char(SYSDATE,'yyyy-MM-dd HH:mm:ss.S')) < 3
  774. );
  775. --122 重点银行 Label120 重点银行 判断逻辑不详 保单的销售渠道网点为招商银行
  776. UPDATE shanglifeecif.Individual si1 SET si1.Label120 = '重点银行' WHERE
  777. si1.scustid IN (SELECT p.customerno FROM dsj.policy_information p WHERE p.AGENTCOM LIKE '%招商银行%');
  778. EXCEPTION
  779. WHEN HIVE_EXCEPTION THEN
  780. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  781. WHEN Others THEN
  782. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  783. END