count_sale33.sql 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. SELECT sum(zhutui_amount), sum(liandai_amount1), sum(liandai_amount2) from
  2. (
  3. select
  4. s.bill_no,sg.quantity*sg.sales_price as zhutui_amount
  5. from rbp.rbp_sales_order_bill s final
  6. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  7. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  8. left join rbp.rbp_goods g on ss.goods_id = g.id
  9. left join rbp.rbp_color cl on ss.color_id = cl.id
  10. 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'
  11. ) as zhutui_bill_no
  12. join
  13. (
  14. select
  15. s.bill_no,sg.quantity*sg.sales_price as liandai_amount1
  16. from rbp.rbp_sales_order_bill s final
  17. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  18. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  19. left join rbp.rbp_goods g on ss.goods_id = g.id
  20. left join rbp.rbp_color cl on ss.color_id = cl.id
  21. where ss.goods_id = goods_id_holder AND ss.color_id = color_id_holder and sg.type = 0 and s.bill_date >= 'date_start_holder' and s.bill_date < 'date_end_holder'
  22. ) as liandai_bill_no1 on zhutui_bill_no.bill_no = liandai_bill_no1.bill_no
  23. join
  24. (
  25. select
  26. s.bill_no,sg.quantity*sg.sales_price as liandai_amount2
  27. from rbp.rbp_sales_order_bill s final
  28. left join rbp.rbp_sales_order_bill_goods sg on s.id = sg.bill_id
  29. left join rbp.rbp_sales_order_bill_size ss on s.id = ss.bill_id and sg.id = ss.bill_goods_id
  30. left join rbp.rbp_goods g on ss.goods_id = g.id
  31. left join rbp.rbp_color cl on ss.color_id = cl.id
  32. where ss.goods_id = goods_third_id_holder AND ss.color_id = color_third_id_holder and sg.type = 0 and s.bill_date >= 'date_start_holder' and s.bill_date < 'date_end_holder'
  33. ) as liandai_bill_no2 on liandai_bill_no1.bill_no = liandai_bill_no2.bill_no