Select a.*,
isnull(b.实收数量,0) as 实收数量
from A1 a
left join
(select 物料编码, sum(实收数量) as 实收数量
from A2 group by 物料编码 ) b
on a.物料编码=b.物料编码
where a.采购订单 = '001'
isnull(b.实收数量,0) as 实收数量
from A1 a
left join
(select 物料编码, sum(实收数量) as 实收数量
from A2 group by 物料编码 ) b
on a.物料编码=b.物料编码
where a.采购订单 = '001'
数据库下载:
https://files.cnblogs.com/sik/Test.rar