select a.编号,a.客户,b.A货数,c.B货数,b.A金额+c.B金额 as 总价
from 主表 as a
inner join
(select 编号,sum(数量) as A货数,sum(数量*单价) as A金额 from 子表 where Left(货物,1)="A" group by 编号) as b
on b.编号=a.编号
inner join
(select 编号,sum(数量) as B货数,sum(数量*单价) as B金额 from 子表 where Left(货物,1)="B" group by 编号) as c
on c.编号=a.编号