一张桌子: 物品(编号,价格)
有一行: id:1,价格:565.8
SELECT price FROM items给予而不是我期望的565.8 SELECT SUM(price) FROM items给予。565.799987792969``565.8
SELECT price FROM items
565.8
SELECT SUM(price) FROM items
565.799987792969``565.8
哪里565.799987792969来的?
565.799987792969
我不确定您使用的是哪个版本,但是听起来像此链接描述了您正在体验的版本。
从链接:
mysql> select * from aaa; +----+------------+------+ | id | month_year | cost | +----+------------+------+ | 1 | 2002-05-01 | 0.01 | | 2 | 2002-06-01 | 1.65 | | 3 | 2002-07-01 | 0.01 | | 4 | 2002-01-01 | 0.01 | +----+------------+------+ mysql> select id, sum(cost) from aaa group by id; +----+---------------------+ | id | sum(cost) | +----+---------------------+ | 1 | 0.00999999977648258 | | 2 | 1.64999997615814 | | 3 | 0.00999999977648258 | | 4 | 0.00999999977648258 | +----+---------------------+ The SUM function changes 0.01 to 0.00999999977648258.
浮点数被存储为近似值;如果要存储价格,最好使用存储精确值的十进制数据类型。