select sum(采购金额),a.id from 供应商表 as a join 采购主表 as b on a.供应商ID=b.供应商ID join 采购子表 as c on b.订单号=c.订单号
select SUM(iQuantity), a.cVenCode from vendor as a
join po_pomain as b
on a.cVenCode = b.cVenCode
join po_podetails as c
on b.POID = c.POID
group by a.cVenCode
聚合函数的sql(count,sum,avg,min,max),他是对你这个列的值进行计算,所以返回的只有一个值,这时候你在加个cVenCode 列,就会要显示很多行,sqlserver不认识肯定报错啦,加个group by ,是为了来告诉sqlserver,分开来显示这组数据,例如cVenCode 供应商代码,那么加上gourp by 他就会按照你不同供应商进行求和