统计一下哪些数据库的sum函数有计算误差
2004-10-13 12:08
232 查看
方法:create table aa( id char(10),v decimal(18,2));
insert into aa values('1',99999999.99);
插入8192个相同的记录
select sum(v) from aa;
结果是819199999918.08为没有误差
已经检验
mysql 4.0.18有误差
firebird 1.5没有误差
The
In this example,
MySQL stores
The maximum range of
以上文字摘自mysql manual.html,我认为它们是矛盾的。如果decimal的取值范围和double相同,它也就不可能保持额外的精度。
insert into aa values('1',99999999.99);
插入8192个相同的记录
select sum(v) from aa;
结果是819199999918.08为没有误差
已经检验
mysql 4.0.18有误差
firebird 1.5没有误差
The
DECIMALand
NUMERICtypes are implemented as the same type by MySQL. They are used to store values for which it is important to preserve exact precision, for example with monetary data. When declaring a column of one of these types, the precision and scale can be (and usually is) specified; for example: salary DECIMAL(5,2)
In this example,
5is the precision and
2is the scale. The precision represents the number of significant decimal digits that will be stored for values, and the scale represents the number of digits that will be stored following the decimal point.
MySQL stores
DECIMALand
NUMERICvalues as strings, rather than as binary floating-point numbers, in order to preserve the decimal precision of those values. One character is used for each digit of the value, the decimal point (if the scale is greater than 0), and the `-' sign (for negative numbers). If the scale is 0,
DECIMALand
NUMERICvalues contain no decimal point or fractional part.
The maximum range of
DECIMALand
NUMERICvalues is the same as for
DOUBLE, but the actual range for a given
DECIMALor
NUMERICcolumn can be constrained by the precision or scale for a given column. When such a column is assigned a value with more digits following the decimal point than are allowed by the specified scale, the value is converted to that scale. (The precise behavior is operating system-specific, but generally the effect is truncation to the allowable number of digits.) When a
DECIMALor
NUMERICcolumn is assigned a value that exceeds the range implied by the specified (or default) precision and scale, MySQL stores the value representing the corresponding end point of that range.
以上文字摘自mysql manual.html,我认为它们是矛盾的。如果decimal的取值范围和double相同,它也就不可能保持额外的精度。
相关文章推荐
- CSDN数据库被爆 统计CSDN用户都喜欢哪些密码
- oracle 数据库的 预定义角色 有哪些?
- 数据库里写了很多存储过程,想用SQL语句查出哪些存储过程包含字段(如:user_id)
- 当前Oracle数据库热备容灾有哪些产品及解决方案,对它们彼此的特长,各位有何建议?(RealSync)
- SQLServer如何用T—SQL命令查询一个数据库中有哪些表
- 统计数据库大小的方法
- 统计 MySQL 数据库中每个表数据与索引占用的空间大小
- 用质数解决数据库两表需要中间表的问题如此解决更新用户的标签和统计标签使用数量问题。
- 统计一个数据库中每一个表的记录数
- PHP实现数据库统计时间戳按天分组输出数据的方法
- 得到两个数据库 不同的表( 统计列 升级 用户表 表字段相差个数)
- 批处理-统计一下当前目录中到底有多少种类型的文件
- 再总结一下QT常用的简单的数据库命令,复杂的不太用的上。
- 数据库中的范式有哪些
- 用一两句话说一下你对“盒模型”这个概念的理解,和它都涉及到哪些css属性
- 数据库专题——SQL语句统计每天、每月、每年的数据
- Hadoop/MapReduce(单词统计--读写数据库)
- C#数据库操作(阅读器、数据库绑定、修改、统计、分页)
- 数据库哪些情况下适合建索引,哪些情况下不适合建索引
- 不用数据库.网店动态图片统计图片制作