0

我在 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 方的余额:

在此处输入图像描述

4

1 回答 1

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 
于 2013-06-13T09:06:01.977 回答