保单件数分布统计.sql 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. CREATE TABLE shanglifeecif.bdnum_distribution(
  2. id string,
  3. labelName string DEFAULT NULL COMMENT '保单件数名称',
  4. bdnum string DEFAULT NULL COMMENT '保单件数'
  5. ) COMMENT '保单件数分布'
  6. STORED AS ES
  7. with shard number 10
  8. replication 1;
  9. CREATE OR REPLACE PROCEDURE shanglifeecif.bdnum_distribution() IS
  10. DECLARE
  11. BEGIN
  12. delete from shanglifeecif.bdnum_distribution;
  13. insert into shanglifeecif.bdnum_distribution (
  14. id,
  15. labelName,
  16. bdnum
  17. ) SELECT row_number()over(),t.labelName,t.bdnum FROM (
  18. SELECT si.label25 labelName,count(1) bdnum FROM shanglifeecif.individual si GROUP BY si.label25
  19. ) t;
  20. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  21. CASE
  22. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  23. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件保单'
  24. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件保单'
  25. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件保单'
  26. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件保单'
  27. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件保单'
  28. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件保单'
  29. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件保单以上'
  30. END
  31. ) where 1 = 1;
  32. END ;