我在Access数据库中有两个表,[Party]和[Invoice]。我想总结一下所有党派的余额。这是我到目前为止的查询:
select
Party.AccountCode,
Party.AccountDescription,
OpeningBalance+sum(invoiceAmount) as balance,
invoiceDate
from Party,Inovoice
where party.accountCode=Inovice.AccountCode
and invoiceDate>=01-01-2013
and invoiceDate<=30-06-2013
group by
Party.AccountCode,
Party.AccountDescription,
invoiceDate
此查询仅返回[Invoice]表中显示的两方的余额:TOM和JHONS。我想显示所有4个派对的余额:
答案 0 :(得分:0)
使用两个查询。第一个计算总发票金额,第二个计算当事人余额
qrySumInvoiceAmounts:
SELECT
AccountCode
sum(invoiceAmount) as InvoiceBalance,
FROM Invoice
group by
AccountCode,
WHERE invoiceDate>= #01-01-2013#
and invoiceDate<= #30-06-2013#
qryPartyBalance:
SELECT
Party.AccountCode,
Party.AccountDescription,
OpeningBalance + InvoiceBalance,
from Party LEFT JOIN qrySumInvoiceAmounts
ON party.accountCode=qrySumInvoiceAmounts.AccountCode