core_sku_freq22.sql 949 B

123456789101112131415
  1. select
  2. count(concat(ss.goods_id, '_', ss.color_id)) as priamry_goods_count
  3. from rbp.rbp_sales_order_bill s final
  4. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  5. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  6. where s.bill_no in (select
  7. s.bill_no
  8. from rbp.rbp_sales_order_bill s final
  9. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  10. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  11. left join rbp.rbp_goods g on ss.goods_id = g.id
  12. left join rbp.rbp_color cl on ss.color_id = cl.id
  13. 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')
  14. and (ss.goods_id != goods_id_holder OR ss.color_id != color_id_holder)
  15. and s.bill_date >= 'date_start_holder' and s.bill_date < 'date_end_holder' and sg.type = 0 and sg.sales_discount > 0.5;