SQL Server查询来计算供应商
答
select s.SupnName,
TotalPurchase = (select sum(p.Qntty * p.PurchsePrice)
from ProductsTble p
where p.supid = s.supid),
TotalPayement = (select sum(c.Cashvalue)
from CashMovementTbl c
where c.supid = s.supid)
from SuppliersTble s;
请确保您有索引ProductsTble(supid)
和CashMovementTbl(supid)
感谢RichardTheKiwi,它工作正常 – 2013-05-02 10:44:55