From: Peter Brawley Date: April 5 2008 4:32pm Subject: Re: Incorrect results from sum List-Archive: http://lists.mysql.com/mysql/212087 Message-Id: <47F7A9AF.5050202@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jonathan, Jake provided useful suggestions & answered your question. For elaboration of Jake's tip, see the manual page for GROUP BY for how joins affect grouping. PB ----- Jonathan Mangin wrote: > > ----- Original Message ----- From: "Jake Peavy" > To: "Jonathan Mangin" > Cc: > Sent: Saturday, April 05, 2008 11:59 AM > Subject: Re: Incorrect results from sum > > >> On 4/5/08, Jonathan Mangin wrote: >>> >>> I'm getting incorrect results from a sum and wonder if >>> anyone sees something obviously wrong. (Won't surprise >>> me.) Leaving 'simple' out of the equation (or adding >>> 'simple' values manually) gets me the correct number. >>> >>> >>> select round(sum($menu.carb * units) + simple.carb,2) > > I was hoping for a syntax error on the above line. This has > worked fine until I added simple. > >>> from itemized inner join simple on itemized.uid = simple.uid >>> inner join $menu on itemized.personal_id = $menu.id >>> where itemized.uid = ? and itemized.date between ? and ? >>> group by date; >>> >>> It's supposed to return 253.08, but I keep getting 260.36. >>> >> >> >> Your "bug" is likely in the GROUP BY. >> >> -- >> -jp >> > There is only one day's meals stored and a difference of 7.28 > relates to no stored values. Thanks anyway. > > >