客户标签label21-40.sql 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.updateIndividualLable_21_40() IS
  2. DECLARE
  3. BEGIN
  4. --18 个人年收入区间 label21 "根据个人年收入字段进行判断:case PIncome when PIncome<=120000 then '低收入' when PIncome>120000 and PIncome<=1000000 then '中产' when --PIncome>1000000 then '富人' else null" 低收入、中产、富人
  5. --根据数据判断单位应该是万元,这里都除以10000做判断
  6. UPDATE shanglifeecif.Individual si1 SET si1.Label21 = (
  7. CASE
  8. WHEN si1.pincome >=0 AND si1.pincome<=12 THEN '低收入'
  9. WHEN si1.pincome >12 AND si1.pincome<=100 THEN '中产'
  10. WHEN si1.pincome > 100 THEN '富人'
  11. else null END
  12. ) where 1 = 1;
  13. --19 拥有车辆数量区间 label22 "根据车辆登录数量字段进行判断:case COVehicle when COVehicle=0 then '无车' when COVehicle=1 then '1辆车' when COVehicle>1 then '2辆车以上'
  14. --else null" 无车,1辆车,2辆车及以上
  15. UPDATE shanglifeecif.Individual si1 SET si1.Label22 = (
  16. CASE
  17. WHEN si1.COVehicle ==0 THEN '无车'
  18. WHEN si1.COVehicle == 1 THEN '1辆车'
  19. WHEN si1.COVehicle > 1 THEN '2辆车以上'
  20. ELSE NULL END
  21. ) where 1 = 1;
  22. --20 拥有住房套数 label23 "根据房屋登录数量字段进行判断:case CORP when CORP=0 then '无房' when CORP=1 then '1套房' when CORP>1 then '2套房以上'
  23. --else null" 无房,1套房,2套房及以上
  24. UPDATE shanglifeecif.Individual si1 SET si1.Label23 = (
  25. CASE
  26. WHEN si1.CORP ==0 THEN '无房'
  27. WHEN si1.CORP == 1 THEN '1套房'
  28. WHEN si1.CORP > 1 THEN '2套房以上'
  29. else null END
  30. ) where 1 = 1;
  31. --21 是否持有寿险有效保单 label24 筛选客户名下所有保单,保单中客户为投保人,保单险种大类为寿险 持有寿险有效保单
  32. UPDATE shanglifeecif.Individual si1 SET si1.label24 = '持有寿险有效保单' WHERE si1.scustid in
  33. (SELECT p.customerno FROM policy_information p,lmriskapp l WHERE p.riskcode = l.riskcode AND p.appflag = '有效' AND l.kindcode = 'L');
  34. --22 保单件数区间 label25 "判断客户作为投保人所有的保单数量(有效保单数量+失效保单数量):NOVPolicy+NOIVPolicy=pCount(保单总件数)
  35. --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件'
  36. --when pCount>10 and pCount<21 then '10-20件'when pCount>20 and pCount<51 then '21-50件'
  37. --when pCount>50 then '50件以上' else '无保单'" 无保单、1件保单、2件保单、3-5件保单、6-10件保单、11-20件保单、20-50件保单、50件以上保单
  38. --第一步 更新 Individual.NOVPolicy 有效记录数
  39. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = (SELECT nvl(t.cnum,0) FROM (
  40. SELECT p.customerno,count(*) AS cnum FROM policy_information p WHERE p.appflag = '有效' GROUP BY p.customerno
  41. ) t WHERE t.customerno = si1.scustid);
  42. --第二步 更新 Individual.NOIVPolicy 无效记录数
  43. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = (SELECT nvl(t.cnum,0) FROM (
  44. SELECT p.customerno,count(*) AS cnum FROM policy_information p WHERE p.appflag <> '有效' GROUP BY p.customerno
  45. ) t WHERE t.customerno = si1.scustid);
  46. --第三步
  47. --UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  48. --CASE
  49. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  50. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件'
  51. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件'
  52. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件'
  53. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件'
  54. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件'
  55. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件'
  56. --WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件以上'
  57. --END ) where 1 = 1;
  58. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  59. CASE
  60. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  61. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件保单'
  62. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件保单'
  63. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件保单'
  64. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件保单'
  65. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件保单'
  66. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件保单'
  67. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件保单以上'
  68. END
  69. ) where 1 = 1;
  70. --23 是否贷款 label26 筛选客户为投保人的有效保单,且办理了贷款业务 有贷款
  71. --24 是否有极短意保单/是否仅有极短意保单 label27 "客户为保单投保人 case AGRMNTAge(保险期限) when avg(sum(AGRMNTAges))<90 then '仅极短意外险'
  72. --when AGRMNTAge<90 then '有极短意外险'" 仅极短意外险,有极短意外险 志广说只用判断有极短意外险不用判断仅有
  73. UPDATE shanglifeecif.Individual si1 SET si1.Label27 = (
  74. SELECT
  75. CASE
  76. WHEN temp.cnt >0 THEN
  77. '有极短意外险'
  78. END
  79. FROM
  80. (
  81. SELECT
  82. count(1) cnt,
  83. policy.customerno
  84. FROM
  85. policy_information policy
  86. where
  87. policy.SECURITY in('7天','15天','30天','90天','1月','3月')
  88. and
  89. policy.riskperiod='短期险'
  90. and
  91. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  92. GROUP BY
  93. policy.customerno
  94. ) temp
  95. WHERE temp.customerno = si1.scustid
  96. );
  97. --29 是否有趸交保单 Label29 有趸交保单 NOSPInsurance,POLICY_INFORMATION.PAYINTV='趸缴',PREMIUM_LIST.PAYMENT_PERIOD='一次交清'
  98. UPDATE shanglifeecif.Individual si1 SET si1.Label29 = '有趸交保单' WHERE si1.scustid IN (
  99. SELECT p.customerno FROM policy_information p WHERE p.payintv = '趸缴' AND p.contno IN (SELECT l.contno FROM PREMIUM_LIST l WHERE l.PAYMENT_PERIOD LIKE '%一次交清 %')
  100. );
  101. --30 是否给本人投保 Label30 仅本人投保,本人已投保,本人未投保 Iself
  102. UPDATE shanglifeecif.Individual si1 SET si1.Label30 = (
  103. SELECT
  104. CASE
  105. WHEN tt.bnum = 0 THEN '本人未投保'
  106. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '本人已投保'
  107. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅本人投保'
  108. END
  109. FROM (
  110. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  111. SELECT count(*) AS bnum,p.customerno FROM policy_information p WHERE p.relationtoappnt = '本人' GROUP BY p.customerno
  112. ) t LEFT JOIN policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  113. ) tt WHERE tt.customerno = si1.scustid
  114. );
  115. --32 是否给父母投保 Label31 仅父母投保,父母已投保,父母未投保 Iparent
  116. UPDATE shanglifeecif.Individual si1 SET si1.Label31 = (
  117. SELECT
  118. CASE
  119. WHEN tt.bnum = 0 THEN '父母未投保'
  120. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '父母已投保'
  121. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅父母投保'
  122. END
  123. FROM (
  124. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  125. SELECT count(*) AS bnum,p.customerno FROM policy_information p WHERE p.relationtoappnt = '父母' GROUP BY p.customerno
  126. ) t LEFT JOIN policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  127. ) tt WHERE tt.customerno = si1.scustid
  128. );
  129. --34 是否给子女投保 Label32 仅子女投保,子女已投保,子女未·投保 Ichildren
  130. UPDATE shanglifeecif.Individual si1 SET si1.Label32 = (
  131. SELECT
  132. CASE
  133. WHEN tt.bnum = 0 THEN '子女未投保'
  134. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '子女已投保'
  135. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅子女投保'
  136. END
  137. FROM (
  138. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  139. SELECT count(*) AS bnum,p.customerno FROM policy_information p WHERE p.relationtoappnt = '子女' GROUP BY p.customerno
  140. ) t LEFT JOIN policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  141. ) tt WHERE tt.customerno = si1.scustid
  142. );
  143. --36 是否给配偶投保 Label33 仅配偶投保,配偶已投保,配偶未投保 Imate
  144. UPDATE shanglifeecif.Individual si1 SET si1.Label33 = (
  145. SELECT
  146. CASE
  147. WHEN tt.bnum = 0 THEN '配偶未投保'
  148. WHEN tt.bnum > 0 and tt.bnum <> tt.tnum THEN '配偶已投保'
  149. WHEN tt.bnum > 0 and tt.bnum = tt.tnum THEN '仅配偶投保'
  150. END
  151. FROM (
  152. SELECT t.customerno,MAX(t.bnum) bnum,count(*) as tnum FROM (
  153. SELECT count(*) AS bnum,p.customerno FROM policy_information p WHERE p.relationtoappnt = '配偶' GROUP BY p.customerno
  154. ) t LEFT JOIN policy_information pi ON pi.customerno = t.customerno GROUP BY t.customerno
  155. ) tt WHERE tt.customerno = si1.scustid
  156. );
  157. EXCEPTION
  158. WHEN HIVE_EXCEPTION THEN
  159. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  160. WHEN Others THEN
  161. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  162. END