险种大类统计.sql 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.riskcode_statistics() IS
  12. DECLARE
  13. BEGIN
  14. delete from shanglifeecif.riskcode_statistics;
  15. insert into shanglifeecif.riskcode_statistics (
  16. id,
  17. kindcode,
  18. kindNAme,
  19. khnum,
  20. tatolprem
  21. ) --险种大类统计
  22. SELECT row_number()over(),temp.kindcode,temp.kindname,temp.khnum,temp.totalPrem FROM (
  23. SELECT sl.kindcode,
  24. (CASE sl.kindcode
  25. WHEN 'A' THEN '意外伤害险'
  26. WHEN 'U' THEN '万能保险'
  27. WHEN 'R' THEN '年金保险'
  28. WHEN 'S' THEN '重疾保险'
  29. WHEN 'L' THEN '人寿保险'
  30. WHEN 'H' THEN '健康险'
  31. END) AS kindname,
  32. count(spi.idno) AS khnum,nvl(sum(spi.prem),0) AS totalPrem FROM shanghailifeecif.lmriskapp sl
  33. LEFT JOIN shanghailifeecif.policy_information spi ON spi.riskcode = sl.riskcode
  34. GROUP BY sl.kindcode
  35. ) temp
  36. /*SELECT row_number()over(),tt.riskcode,tt.riskname,tt.khnum,tt.totalPrem FROM (
  37. SELECT sl.riskcode,sl.riskname,count(spi.idno) AS khnum,sum(spi.prem) AS totalPrem FROM shanghailifeecif.lmriskapp sl
  38. LEFT JOIN shanghailifeecif.policy_information spi ON spi.riskcode = sl.riskcode
  39. GROUP BY sl.riskcode,sl.riskname
  40. ) tt WHERE tt.khnum > 0 AND tt.totalPrem >0*/
  41. /*SELECT slk.kindcode,sum(temp.khnum),sum(totalPrem) FROM (
  42. SELECT sl.riskcode,sl.riskname,count(spi.idno) AS khnum,sum(spi.prem) AS totalPrem FROM shanghailifeecif.lmriskapp sl
  43. LEFT JOIN shanghailifeecif.policy_information spi ON spi.riskcode = sl.riskcode
  44. GROUP BY sl.riskcode,sl.riskname
  45. ) temp LEFT JOIN shanghailifeecif.lmriskapp slk ON slk.riskcode = temp.riskcode
  46. GROUP BY slk.kindcode*/
  47. END ;