-------------更新 select t.wh_to_id,t.barcode,count(t.barcode) from tb_usc_material_flow t where t.barcode is not null having count(t.barcode) > 2 group by t.wh_to_id,t.barcode select t.wh_to_id,t.barcode,count(t.barcode),sum(t.quantity) from tb_usc_material_flow t where t.barcode is not null having count(t.barcode) =1 and sum(t.quantity)=-1 group by t.wh_to_id,t.barcode select wh_to_id,t.material_id,sum(t.quantity) from tb_usc_material_flow t where t.barcode is null /* and t.wh_from_id is not null and t.wh_to_id is not null*/ and t.doc_type_code not in ('16')--拆零 having sum(t.quantity) <0 group by t.wh_to_id ,t.material_id select t.* from tb_usc_material_flow t where (wh_to_id,material_id) in( select t.wh_to_id,t.material_id from tb_usc_material_flow t where t.barcode is null and t.doc_type_code not in ('16') and t.wh_to_id not in(select wh_id from tb_usc_warehouse wu where wu.wh_type='lv1' ) having sum(t.quantity)!=0 group by t.wh_to_id,t.material_id)