MySQL Forums
Forum List  »  Newbie

Re: Determine Balance Due from Two Tables
Posted by: Jay Pipes
Date: June 30, 2005 02:44PM

Try:

SELECT
c.clientid
, concat(c.lastname, ", ",c.firstname) as name
, SUM(IFNULL(r.amount, 0)) as totalcost
, SUM(IFNULL(p.amount, 0)) as totalpaid
, (SUM(IFNULL(r.amount, 0)) -SUM(IFNULL(p.amount, 0))) as balance
FROM tblclient c
LEFT JOIN tblregistration r
ON c.clientid = r.clientid
LEFT JOIN tblpayment p
ON c.clientid = p.clientid
GROUP BY c.clientid
ORDER BY name

Jay Pipes
Community Relations Manager, North America, MySQL Inc.

Got Cluster? http://www.mysql.com/cluster
Personal: http://jpipes.com

Options: ReplyQuote


Subject
Written By
Posted
Re: Determine Balance Due from Two Tables
June 30, 2005 02:44PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.