--出库24个单据不存在 select * from tb_usc_export_master mst,tb_usc_export_detail dtl where (mst.status in('04') or mst.status is null) and mst.export_master_id = dtl.export_master_id and mst.export_master_id not in( select mst1.doc_no from tb_usc_material_flow mst1 ) --出库流水 select tt.export_master_id, tt.wh_to_id,tt.material_id, tt.quantity,tt.import_quantity,'出库' type from ( select M1.export_master_id, M2.wh_to_id, M1.import_quantity, M1.material_id, M1.package_units_name, M2.quantity, M2.package_units_name from (select dtl.export_master_id, dtl.material_id, dtl.package_units_code, dtl.package_units_name, mst.doc_type_code, mst.wh_from_id, sum(dtl.export_quantity) import_quantity from tb_usc_export_master mst, tb_usc_export_detail dtl where (mst.status in('04') or mst.status is null) and mst.export_master_id = dtl.export_master_id group by dtl.export_master_id, dtl.material_id, mst.doc_type_code, dtl.package_units_code, mst.wh_from_id, dtl.package_units_name) M1, (select mst1.doc_no, mst1.material_id, mst1.doc_type_code, mst1.package_units_code, mst1.package_units_name, sum(mst1.quantity) quantity, /* mst1.wh_from_id,*/ mst1.wh_to_id from tb_usc_material_flow mst1 group by mst1.doc_no, mst1.material_id, mst1.doc_type_code, mst1.package_units_code, mst1.package_units_name, /* mst1.wh_from_id,*/ mst1.wh_to_id) M2 WHERE M1.export_master_id = M2.doc_no(+) AND M1.material_id = M2.material_id(+) AND M1.doc_type_code = M2.doc_type_code(+) AND M1.wh_from_id = M2.wh_to_id(+) ) tt where tt.quantity+tt.import_quantity!=0 or tt.quantity is null ---确认 select * from tb_usc_material_flow where doc_no in ('CK201705261002541') and material_id = '684000000000736' for update /* and doc_type_code != '02'*/ select dtl.export_master_id, dtl.material_id, dtl.package_units_code, dtl.package_units_name, mst.doc_type_code, mst.wh_from_id, sum(dtl.export_quantity) import_quantity from tb_usc_export_master mst, tb_usc_export_detail dtl where (mst.status in('04') or mst.status is null) and mst.export_master_id = dtl.export_master_id and dtl.export_master_id='CK201705221002723' and dtl.material_id = '941000000005596' group by dtl.export_master_id, dtl.material_id, mst.doc_type_code, dtl.package_units_code, mst.wh_from_id, dtl.package_units_name