险种大类统计.sql 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. CREATE TABLE shanglifeecif.riskcode_statistics(
  2. id string,
  3. kindcode string DEFAULT NULL COMMENT '险种大类代码',
  4. kindNAme string DEFAULT NULL COMMENT '险种大类名称',
  5. khnum string DEFAULT NULL COMMENT '客户数量',--pwcomp ,-- '承保分公司 HEALTH_INSURANCE_LISTING.AGENTGROUPAREA 营业区HEALTH_INSURANCE_LISTING.AGENTGROUP 营业部',
  6. tatolprem string DEFAULT NULL COMMENT '总保额'
  7. ) COMMENT '险种大类统计表'
  8. STORED AS ES
  9. with shard number 10
  10. replication 1;
  11. CREATE OR REPLACE PROCEDURE shanglifeecif.customertotaltemp() IS
  12. DECLARE
  13. BEGIN
  14. DELETE FROM shanglifeecif.customertotaltemp;
  15. insert into shanglifeecif.customertotaltemp(
  16. scustid,
  17. name,
  18. gender,
  19. birthday,
  20. idcard,
  21. idtype
  22. )
  23. SELECT
  24. scustid ,
  25. max(name) as name,
  26. max(gender) as gender ,
  27. to_char(max(birthday),"yyyy-MM-dd") birthday,
  28. max(idcard) as idcard,
  29. max(idtype) AS idtype
  30. FROM (
  31. SELECT
  32. trim(customerno) AS scustid,--投保人
  33. trim(name) AS name,
  34. trim(sex) AS gender,
  35. trim(birthday) AS birthday,
  36. trim(idtype) AS idtype ,
  37. trim(idno) AS idcard
  38. FROM
  39. dsj.policy_information
  40. WHERE customerno IS NOT NULL
  41. UNION
  42. SELECT
  43. trim(insuredno) AS scustid,--被保人
  44. trim(insuredname) AS name,
  45. trim(insuredsex) AS gender,
  46. trim(insuredbirthday) AS birthday,
  47. trim(insuredidtype) AS idtype ,
  48. trim(insuredidno) AS idcard
  49. FROM
  50. dsj.policy_information
  51. WHERE insuredno IS NOT NULL
  52. ) tmpTable GROUP BY scustid;
  53. UPDATE shanglifeecif.customertotaltemp sct SET sct.mobile = (SELECT trim(t.MOBILE) FROM dsj.t_customer_class t WHERE sct.scustid=t.customer_id);
  54. EXCEPTION
  55. WHEN HIVE_EXCEPTION THEN
  56. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  57. WHEN Others THEN
  58. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  59. END ;
  60. CREATE OR REPLACE PROCEDURE shanglifeecif.customer_risk_temp()
  61. IS
  62. DECLARE
  63. BEGIN
  64. DELETE FROM shanglifeecif.customer_risk_temp;
  65. INSERT INTO shanglifeecif.customer_risk_temp(
  66. id,
  67. scustid,
  68. name,
  69. gender,
  70. idcard,
  71. birthday,
  72. policyno,
  73. productname,
  74. riskcategoriesname,
  75. risk
  76. )
  77. SELECT
  78. row_number()over(),
  79. si.scustid,
  80. si.name,
  81. CASE si.gender
  82. WHEN '0' THEN '男'
  83. WHEN '1' THEN '女'
  84. END AS gender,
  85. si.idcard,
  86. to_char(si.birthday,"yyyy-MM-dd") birthday,
  87. sit.policyno,
  88. sit.productname,
  89. sit.risk_categories_name,
  90. sit.Risk
  91. FROM shanglifeecif.individual si
  92. LEFT JOIN shanglifeecif.insurancearrangement sit ON si.scustid = sit.applicantscustid;
  93. EXCEPTION
  94. WHEN HIVE_EXCEPTION THEN
  95. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  96. WHEN Others THEN
  97. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  98. END ;
  99. /
  100. CREATE OR REPLACE PROCEDURE shanglifeecif.riskcode_statistics() IS
  101. DECLARE
  102. BEGIN
  103. DELETE FROM shanglifeecif.riskcode_statistics;
  104. insert into shanglifeecif.riskcode_statistics (
  105. id,
  106. kindName,
  107. khnum,
  108. tatolprem
  109. ) --险种大类统计
  110. SELECT
  111. row_number()over(),
  112. temp.kindName,
  113. temp.khnum,
  114. temp.tatolprem
  115. FROM (
  116. SELECT
  117. crt.riskcategoriesname AS kindName,
  118. count(DISTINCT scustid) AS khnum,
  119. sum(risk) AS tatolprem
  120. FROM shanglifeecif.customer_risk_temp crt
  121. WHERE crt.riskcategoriesname IS NOT null
  122. GROUP BY crt.riskcategoriesname
  123. ) temp;
  124. EXCEPTION
  125. WHEN HIVE_EXCEPTION THEN
  126. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  127. WHEN Others THEN
  128. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  129. END ;
  130. /*
  131. CREATE OR REPLACE PROCEDURE shanglifeecif.riskcode_statistics() IS
  132. DECLARE
  133. BEGIN
  134. DELETE FROM shanglifeecif.riskcode_statistics;
  135. insert into shanglifeecif.riskcode_statistics (
  136. id,
  137. kindName,
  138. khnum,
  139. tatolprem
  140. ) --险种大类统计
  141. SELECT
  142. row_number()over(),
  143. temp.kindName,
  144. temp.khnum,
  145. temp.tatolprem
  146. FROM (
  147. select
  148. a.risk_categories_name AS kindName ,
  149. count(*) AS khnum,
  150. nvl(sum(a.prem),0) AS tatolprem
  151. FROM shanglifeecif.insurancearrangement a GROUP BY a.risk_categories_name
  152. ) temp;
  153. insert into shanglifeecif.riskcode_statistics (
  154. id,
  155. kindcode,
  156. kindNAme,
  157. khnum,
  158. tatolprem
  159. ) --险种大类统计
  160. SELECT row_number()over(),temp.kindcode,temp.kindname,temp.khnum,temp.totalPrem FROM (
  161. SELECT sl.kindcode,
  162. (CASE sl.kindcode
  163. WHEN 'A' THEN '意外伤害险'
  164. WHEN 'U' THEN '万能保险'
  165. WHEN 'R' THEN '年金保险'
  166. WHEN 'S' THEN '重疾保险'
  167. WHEN 'L' THEN '人寿保险'
  168. WHEN 'H' THEN '健康险'
  169. END) AS kindname,
  170. count(spi.idno) AS khnum,nvl(sum(spi.prem),0) AS totalPrem FROM lmriskapp sl
  171. LEFT JOIN policy_information spi ON spi.riskcode = sl.riskcode
  172. GROUP BY sl.kindcode
  173. ) temp;
  174. EXCEPTION
  175. WHEN HIVE_EXCEPTION THEN
  176. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  177. WHEN Others THEN
  178. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  179. END ;
  180. */