[V4RB+Vserve] SUM on 2 tables

Eric Ferrer wonderfef at noos.fr
Tue Nov 16 16:05:42 CST 2004


Hello all,

I have 3 tables (with fields):
Customers (ID, Name)
Invoices (ParentCustomerID, Value)
Payments (ParentCustomerID, Value)

I'd need to get from a single SQLselect the balance of each customer.

SELECT
SUM(Invoices.Value) - SUM(Payments.Value),
Clients.Name
FROM Invoices, Payments, Customers
WHERE
Invoices.ParentCustomerID *= Customers.ID
OR
Payments.ParentCustomerID *= Customers.ID
GROUP BY
Invoices.ParentCustomerID,
Payments.ParentCustomerID
ORDER BY 1 DESC

... But this is not possible
Any clue?

Thanks in advance
Eric




More information about the Valentina mailing list