Ville Mattila wrote:
I try to get a list of all Invoices with total sum of the invoice and
paid sum of each invoices, as well as a customer name. I try following
query:
SELECT Invoices.*, SUM(InvoiceContents.Amount * InvoiceContents.Price)
AS InvoiceTotal, Customers.Name, SUM(Payments.Amount) Pa
Ville,
>SELECT Invoices.*, SUM(InvoiceContents.Amount * InvoiceContents.Price)
>AS InvoiceTotal, Customers.Name, SUM(Payments.Amount) PaidTotal,
>MAX(Payments.Date) LastPayment FROM Invoices LEFT JOIN InvoiceContents
>ON (InvoiceContents.InvoiceID = Invoices.ID) LEFT JOIN Customers ON
>(Customers