发现mysql 4.0.18 for nt 的sum函数的计算误差

发现mysql 4.0.18 for nt 的sum函数的计算误差
mysql> create table ch3(ID char(32), V decimal(18,2));
Query OK, 0 rows affected (0.12 sec)

mysql> insert into ch3 select * from vc2;
Query OK, 8192 rows affected (1.24 sec)
Records: 8192  Duplicates: 0  Warnings: 0


mysql> select max(v) from ch3;
+-------------+
| max(v)      |
+-------------+
| 99999999.99 |
+-------------+
1 row in set (1.17 sec)

mysql> select min(v) from ch3;
+-------------+
| min(v)      |
+-------------+
| 99999999.99 |
+-------------+
1 row in set (1.17 sec)
mysql> select sum(v) from ch3;
+-----------------+
| sum(v)          |
+-----------------+
| 819199999918.02 |
+-----------------+
1 row in set (0.08 sec)

mysql> update ch3 set v=100000000;
Query OK, 8192 rows affected (0.12 sec)
Rows matched: 8192  Changed: 8192  Warnings: 0

mysql> select sum(v) from ch3;
+-----------------+
| sum(v)          |
+-----------------+
| 819200000000.00 |
+-----------------+
1 row in set (0.06 sec)

mysql> update ch3 set v=100000000-0.01;
Query OK, 8192 rows affected (0.25 sec)
Rows matched: 8192  Changed: 8192  Warnings: 0

mysql> select sum(v) from ch3;
+-----------------+
| sum(v)          |
+-----------------+
| 819199999918.02 |
+-----------------+
1 row in set (0.08 sec)

mysql> update ch3 set v=100000000+0.01;
Query OK, 8192 rows affected (0.23 sec)
Rows matched: 8192  Changed: 8192  Warnings: 0

mysql> select sum(v) from ch3;
+-----------------+
| sum(v)          |
+-----------------+
| 819200000081.98 |
+-----------------+
1 row in set (0.09 sec)
mysql> select 99999999.99*8192;
+------------------+
| 99999999.99*8192 |
+------------------+
|  819199999918.08 |
+------------------+
1 row in set (0.00 sec)

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值