Advertisement
Pandaaaa906

询报价相似度

Oct 26th, 2022
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 品牌,货号,英文名,中文名,规格
  2. --
  3.  
  4. with target as (
  5. SELECT
  6. inq_m.id,
  7. inq_m.create_time,
  8. count(distinct inq_d.id) c
  9. FROM t_inq_order inq_m
  10. LEFT JOIN t_inq_order_detail inq_d
  11. ON inq_m.id = inq_d.inq_order_id
  12.  
  13. where inq_m.id='4463064887204708352'   -- 输入
  14. GROUP BY inq_m.id
  15. )
  16.  
  17. SELECT
  18. inq_d.inq_order_id,
  19. -- avg(similarity(inq_d.brand_name, target_d.brand_name)) brand_sim,
  20. -- sum(similarity(inq_d.brand_no, target_d.brand_no)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) cat_no_sim,
  21. -- sum(similarity(inq_d.en_name, target_d.en_name)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) en_name_sim,
  22. -- sum(similarity(inq_d.cn_name, target_d.cn_name)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) cn_name_sim,
  23. -- sum(similarity(inq_d.cas, target_d.cas)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) cas_sim,
  24. max(target.c),
  25. count(distinct inq_d.id),
  26. sum(similarity(inq_d.brand_no, target_d.brand_no)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) +
  27. GREATEST(
  28.     sum(similarity(inq_d.en_name, target_d.en_name)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))),
  29.     sum(similarity(inq_d.cn_name, target_d.cn_name)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id)))
  30. )+
  31. sum(similarity(inq_d.cas, target_d.cas)) / (max(target.c)+abs(max(target.c)-count(distinct inq_d.id))) sim
  32.  
  33. FROM t_inq_order_detail inq_d, target
  34.  
  35. LEFT JOIN t_inq_order_detail target_d
  36. ON target.id = target_d.inq_order_id
  37.  
  38. where inq_d.create_time > target.create_time - interval '1 month'
  39. and inq_d.inq_order_id != target.id  -- 剔除源记录
  40.  
  41. GROUP BY inq_d.inq_order_id
  42. -- having sim > 10
  43.  
  44. -- ORDER BY cat_no_sim desc nulls last
  45. ORDER BY sim desc nulls last
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement