[thelist] MySQL calculations

Tab Alleman Tab.Alleman at MetroGuide.com
Wed Jun 16 12:27:49 CDT 2004


Michael Pemberton wrote:
> Tab Alleman wrote:
> SELECT `cust`.`custid` , `invoiceid` , `name` , sum( CASE
> WHEN `quantity` = 0 THEN `amount`
> WHEN `quantity` IS NULL THEN `amount`
> ELSE `amount` * `quantity`
> END ) as outstanding
> FROM sales, cust
> WHERE `sales`.`custid` = `cust`.`custid` AND (`paid` IS NULL OR
> `paid` = '0000-00-00' )
> GROUP BY `cust`.`custid`, `invoiceid`
> ORDER BY `cust`.`custid`


...Another solution could have been to UNION the two queries, but I
think CASE is much cooler.



More information about the thelist mailing list