LEFT Join未在MS Access中返回记录
本文关键字:返回 记录 Access MS Join 未在 LEFT | 更新日期: 2023-09-27 18:23:57
我最近的项目要求打印应收账款摘要。我需要返回OpeningBalance
表中的整行以及VoucherHeader
和Customers
中的匹配行。
我的SQL查询是这个
SELECT
OpeningBalance.OpenID, Sum(OpeningBalance.Amount) AS SumOfAmount,
Sum(VoucherHeader.Debit) AS SumOfDebit, Sum(VoucherHeader.Credit) AS SumOfCredit,
Customers.CustomerID, Customers.CustomerName
FROM
(OpeningBalance
LEFT OUTER JOIN
VoucherHeader ON OpeningBalance.OpenID = VoucherHeader.LedgerID)
INNER JOIN
Customers ON OpeningBalance.OpenID = Customers.CustomerID
WHERE
(((Customers.CustomerType)='Debtor')
AND ((VoucherHeader.VoucherDate)<#2013/06/02#))
GROUP BY
OpeningBalance.OpenID, Customers.CustomerID, Customers.CustomerName,
VoucherHeader.LedgerID
ORDER BY
Customers.CustomerName;
请帮忙。
SELECT OB.OpenID, Sum(OB.Amount) AS SumOfAmount,
Sum(VB.Debit) AS SumOfDebit, Sum(VB.Credit) AS SumOfCredit, CS.CustomerID,
CS.CustomerName FROM OpeningBalance OB
LEFT OUTER JOIN VoucherHeader VB ON OB.OpenID = VB.LedgerID
LEFT OUTER JOIN Customers CS ON OB.OpenID = CS.CustomerID
WHERE (((CS.CustomerType)='Debtor') AND ((VB.VoucherDate)<#2013/06/02#))
GROUP BY OB.OpenID, CS.CustomerID, CS.CustomerName, VB.LedgerID
ORDER BY CS.CustomerName;