LEFT JOIN (SELECT Produce_Code,Material_Code,SUM(Plan_Number) Plan_Number FROM ods_procure_out_order GROUP BY Produce_Code,Material_Code)AS out_order ON out_order.Produce_Code= mes_prepare.workorder_name AND out_order.Material_Code=mes_prepare_detail.material_code
LEFT JOIN (SELECT Produce_Code,Material_Code,SUM(Plan_Number) Plan_Number FROM ods_procure_out_order GROUP BY Produce_Code,Material_Code)AS out_order ON out_order.Produce_Code= mes_prepare.workorder_name AND out_order.Material_Code=mes_prepare_detail.material_code