select depot.*, rk.rsl as 入库数量,ck.csl as 出库数量,depot.kc+rk.sl-rck.csl as 当前库存 from depot left outer join (select indepot.bh, sum(indepot.sl) as rsl from indepot group by indepot.bh) as rk on rk.bh=depot.bh left outer join (select outdepot.bh, sum(outdepot.sl) as csl from outdepot group by outdepot.bh) as ck on ck.bh=depot.bh