Re: Joining multiple tables with grouping functions

2006-05-26 Thread Jay Pipes
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

Re: Joining multiple tables with grouping functions

2006-05-26 Thread Peter Brawley
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