0

我最近的项目我有一个打印应收账款摘要的要求。我需要从表中返回整行并从和OpeningBalance中匹配行。VoucherHeaderCustomers

我的 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;

请帮忙。

4

1 回答 1

0
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;
于 2013-07-20T07:45:39.010 回答