相似客户.sql 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.same_customer() -- 创建主存储过程
  2. IS
  3. DECLARE
  4. scount int
  5. BEGIN
  6. DELETE FROM shanglifeecif.samecustomer;
  7. INSERT INTO shanglifeecif.samecustomer(
  8. sid,
  9. scustid,
  10. name,
  11. gender,
  12. birthday,
  13. idcard,
  14. Passport,
  15. Dlicense,
  16. OtherIdNumber,
  17. sameType
  18. )
  19. SELECT
  20. row_number()OVER(),
  21. sc1.scustid,
  22. sc1.name,
  23. sc1.gender,
  24. sc1.birthday,
  25. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  26. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  27. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  28. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  29. 0
  30. FROM shanglifeecif.customertotaltemp sc1
  31. WHERE sc1.mobile IS NOT NULL AND EXISTS (SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc1.scustid != sc2.scustid
  32. AND sc1.name = sc2.name AND sc1.gender = sc2.gender AND sc1.idtype = sc2.idtype AND sc1.mobile = sc2.mobile);
  33. SELECT count(*) INTO scount FROM shanglifeecif.samecustomer;
  34. --三要素疑似相同指姓名、性别、出生日期一致 1
  35. INSERT INTO shanglifeecif.samecustomer(
  36. sid,
  37. scustid,
  38. name,
  39. gender,
  40. birthday,
  41. idcard,
  42. Passport,
  43. Dlicense,
  44. OtherIdNumber,
  45. sameType
  46. )
  47. SELECT
  48. row_number()OVER()+scount,
  49. sc1.scustid,
  50. sc1.name,
  51. sc1.gender,
  52. sc1.birthday,
  53. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  54. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  55. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  56. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  57. 1
  58. FROM shanglifeecif.customertotaltemp sc1
  59. WHERE EXISTS(SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc2.scustid!=sc1.scustid AND sc1.name = sc2.name AND sc1.gender = sc2.gender AND sc1.birthday = sc2.birthday );
  60. SELECT count(*) INTO scount FROM shanglifeecif.samecustomer;
  61. --两要素疑似相同指姓名、证件号码一致 2
  62. INSERT INTO shanglifeecif.samecustomer(
  63. sid,
  64. scustid,
  65. name,
  66. gender,
  67. birthday,
  68. idcard,
  69. Passport,
  70. Dlicense,
  71. OtherIdNumber,
  72. sameType
  73. )
  74. SELECT
  75. row_number()OVER()+scount,
  76. sc1.scustid,
  77. sc1.name,
  78. sc1.gender,
  79. sc1.birthday,
  80. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  81. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  82. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  83. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  84. 2
  85. FROM shanglifeecif.customertotaltemp sc1
  86. WHERE sc1.idcard is not null and EXISTS (SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc2.scustid!=sc1.scustid AND sc1.name = sc2.name AND sc1.idcard = sc2.idcard);
  87. END;