mysql sum函数结果出现多达13位小数的解决方案!

第一次查询结果,小数位有13位!

第一次查询结果,小数位有13位!

解决之后正常查询结果,只有2位!

解决之后正常查询结果,只有2位!

sql语句:

(SELECT SUM(o_g.goods_amount) AS
amount_sum,SUM(o_g.goods_cost*o_g.goods_number) AS
cost_sum,SUM(o_g.goods_number) AS number_sum
FROM erp_order_goods AS o_g
LEFT OUTER JOIN erp_order AS o ON o_g.order_id = o.order_id
LEFT OUTER JOIN erp_goods AS g ON g.gid = o_g.goods_id
LEFT OUTER JOIN erp_brand AS b ON b.brand_id = g.brand_id WHERE
(o.add_time BETWEEN “1389715200” AND “1389772885”) AND (o.order_status=1 OR
o.order_status=2)) UNION ALL
(SELECT SUM(o_a_g.goods_change_amount) AS
amount_sum,SUM(o_a_g.goods_cost*o_a_g.goods_change_number) AS
cost_sum,SUM(o_a_g.goods_change_number) AS number_sum
FROM erp_order_after_goods AS o_a_g
LEFT OUTER JOIN erp_order_after AS o_a ON o_a_g.order_after_id = o_a.order_after_id
LEFT OUTER JOIN erp_goods AS g ON g.gid = o_a_g.goods_id
LEFT OUTER JOIN erp_brand AS b ON b.brand_id = g.brand_id WHERE
(o_a.add_time BETWEEN “1389715200” AND “1389772885”))

解决方案:

将o_a_g.goods_change_amount的字段类型从float(10,2)修改为decimal(10,2)

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/251010.html

(0)
上一篇 2022年5月1日
下一篇 2022年5月1日

相关推荐

发表回复

登录后才能评论