From: Peter Brawley Date: December 17 2008 11:37pm Subject: Re: SUMIF List-Archive: http://lists.mysql.com/mysql/215646 Message-Id: <49498D26.9090803@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------080607030708070304070705" --------------080607030708070304070705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Menachem, > SUM(check_applications.namountapplied IF checks.lvoid=0) Close. Try SUM(IF(checks.lvoid=0,0,check_applications.namountapplied)) PB ----- Menachem Bazian wrote: > Hi, > > I was wondering if anyone can help me with this syntax. I have three > tables, INVOICES, CHECKS and CHECK_APPLICATIONS. I need to SUM the > amounts in CHECK_APPLICATIONS for each invoice IF the check it is > related to has not been voided. Something like this (in SQL and > pseudocode) > > SELECT invoices.id, invoices.vendor, invoices.namount AS nninvoiceamount, > I also need to refer to that SUM in another field. > > invoices.namount - SUM(namountapplied we did before) AS namountleft > > Any ideas? > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - http://www.avg.com > Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 12/17/2008 8:31 AM > > --------------080607030708070304070705--