related_sales.sql 869 B

1234567891011121314151617
  1. select
  2. count(sg.quantity), sum(sg.quantity*sg.sales_price)
  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. left join rbp.rbp_goods g on ss.goods_id = g.id
  7. left join rbp.rbp_color cl on ss.color_id = cl.id
  8. where sg.sales_discount > 0.5 and s.bill_no in (
  9. select
  10. s.bill_no
  11. from rbp.rbp_sales_order_bill s final
  12. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  13. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  14. left join rbp.rbp_goods g on ss.goods_id = g.id
  15. left join rbp.rbp_color cl on ss.color_id = cl.id
  16. 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'
  17. )