Re: SUM(field) sometimes returns -0

Sinisa Milivojevic <[email protected]>
Newsgroups gmane.comp.db.mysql.bugs
Message-ID <[email protected]>
Michael Duncan writes:
> While developing an app I came across this anomoly.
> 
> Just to make sure it wasn't VB/ODBC/Win2K/network/exteneral gremlin/...
> I did the query on the console of the machine running mySQL.
> There are 18 units in this table the ones not listed in the first query 
> do return a valid 0 (+0) balance.
> 
> I can allow for this by double checking the returned data in my app but 
> it shouldn't be happening should it?
> 
> 

[skip]

> -- 
> MySQL Bugs Mailing List
> For list archives: http://lists.mysql.com/bugs
> To unsubscribe:    http://lists.mysql.com/[email protected]


Hi!

First of all, this is a mailing list for fully repeatable test cases,
so in future also send or upload a dump of your table.

I have tested your case (with data inserted  as per your output) and
it worked fine for me:


mysql> select unit, sum(amount) from xx group by unit;
+------+-------------+
| unit | sum(amount) |
+------+-------------+
|    1 |         3.3 |
|    2 |         2.2 |
|    6 |           0 |
+------+-------------+
3 rows in set (0.00 sec)

mysql> select unit, sum(amount) tot from xx group by unit having tot < 0.0;
Empty set (0.03 sec)


This is expected behaviour because MySQL has to rely on the native
compiler and native floating point functions library for all floating
point calculus.

So, results among OS's and CPU/FPU's may differ.

-- 

Sincerely,

--
For technical support contracts, go to https://order.mysql.com/?ref=msmi
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Sinisa Milivojevic <[email protected]>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB
/_/  /_/\_, /___/\___\_\___/   Fulltime Developer and Support Coordinator
       <___/   www.mysql.com   Larnaca, Cyprus


-- 
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.