Home >Database >Mysql Tutorial >mysql中sum float类型使用小数点的方法_MySQL

mysql中sum float类型使用小数点的方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:25:461045browse

bitsCN.com 方法一:最好的办法是将float字段改为decimal(16,6)。具体方法:可设置一个临时字段,结合MySQL的关键字binary进行准确复制等。
方法二:使用binary关键字解决。具体操作为“select sum(binary 字段名(float类型))”
BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串
例子:

    "select sum(a.number*binary(b.price)) as total
        from ler_card as a
        left join ler_items as b on a.itemId=b.itemId
        where user_id=1"
bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn