get_fusion33.sql 1.3 KB

123456789101112131415161718192021222324252627
  1. with temp_member_goods as (
  2. select
  3. distinct s.bill_no bill_no, concat(ss.goods_id,'-', ss.color_id) as ss_gc_id
  4. from rbp.rbp_sales_order_bill s final
  5. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  6. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  7. where s.bill_no in (select
  8. s.bill_no
  9. from rbp.rbp_sales_order_bill s final
  10. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  11. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  12. left join rbp.rbp_goods g on ss.goods_id = g.id
  13. left join rbp.rbp_color cl on ss.color_id = cl.id
  14. where g.code = 'g_code_holder' and cl.`code` = 'cl_code_holder' and sg.type = 0 and s.bill_date >= 'date_start_holder' and s.bill_date < 'date_end_holder')
  15. and (ss.goods_id != goods_id_holder OR ss.color_id != color_id_holder)
  16. and s.bill_date >= 'date_start_holder' and s.bill_date < 'date_end_holder' and sg.type = 0 and sg.sales_discount > 0.5
  17. )
  18. SELECT
  19. o1.ss_gc_id AS ss_gc_id_1,
  20. o2.ss_gc_id AS ss_gc_id_2,
  21. COUNT(*) AS combination_count
  22. FROM temp_member_goods o1
  23. JOIN temp_member_goods o2
  24. ON o1.bill_no = o2.bill_no
  25. AND o1.ss_gc_id < o2.ss_gc_id
  26. GROUP BY o1.ss_gc_id, o2.ss_gc_id
  27. ORDER BY combination_count DESC limit 0, 20;