0

Access データベースに [Party] と [Invoice] の 2 つのテーブルがあります。全パーティのバランスをまとめたいと思います。これまでの私のクエリは次のとおりです。

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] テーブルに表示される 2 つのパーティ (TOM と JHONS) のみの残高を返します。4 つの当事者すべての残高を表示したい:

ここに画像の説明を入力

4

1 に答える 1

0

2 つのクエリを使用します。1 つ目は合計請求額を計算し、2 つ目はパーティ残高を計算します。

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 に答える