select TA.GoodName,(TA.A-isnull(TB.B,0)) as 库存 from ((select GoodName,sum(InNumbers)as A from InTable Group by GoodName )TA left outer join (select GoodsName,sum(OutNumbers) as B from OutNumbers group by GoodsName)TB where TA.GoodName = TB.GoodsName)
改一下 select TA.GoodName,(TA.A-isnull(TB.B,0)) as 库存 from ((select GoodName,sum(InNumbers)as A from InTable Group by GoodName )TA left outer join (select GoodsName,sum(OutNumbers) as B from OutNumbers group by GoodsName)TB on TA.GoodName = TB.GoodsName)
((select GoodName,sum(InNumbers)as A from InTable Group by GoodName )TA left outer join
(select GoodsName,sum(OutNumbers) as B from OutNumbers group by GoodsName)TB
where TA.GoodName = TB.GoodsName)
select TA.GoodName,(TA.A-isnull(TB.B,0)) as 库存 from
((select GoodName,sum(InNumbers)as A from InTable Group by GoodName )TA left outer join
(select GoodsName,sum(OutNumbers) as B from OutNumbers group by GoodsName)TB
on TA.GoodName = TB.GoodsName)