BI同学反馈,他们BI时反馈分析SQL时,count得不到他们要的数据结果。

查了下官网


结论:
整形除以整型,mysql正常情况下当然得到的应该也是整型。
但是在数据库应用中,通常业务的需求是得到NUMERIC,不能直接把小数干掉。
例如1除以34,如果是整型除法会得到0,然而用户可能要的是小数。
1、建议用户使用float8, money, numeric来存储这种数值。
2、或者在相除时,对操作数类型进行转换。
postgres=# select 1/34::float;
?column?
----------------------
0.029411764705882353
(1 row)
postgres=# select floor(1)/34
;
?column?
----------------------
0.029411764705882353
(1 row)
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |