Mysql SUM Float给出了错误的值

时间:2014-02-01 09:51:27

标签: mysql join sum

我有下一个查询:

SELECT DATE_FORMAT(stats_visits.date,'%H') AS zdate,
   count(DISTINCT stats_visits.id) AS visits,
   count(DISTINCT d.id) AS downloads,
   count(DISTINCT c.id) AS clicks,
   ROUND(SUM(d.revenue),3) AS zrevenue
FROM stats_visits
LEFT JOIN stats_downloads AS d on(DATE_FORMAT(d.date,'%y/%m/%d %H') = DATE_FORMAT(stats_visits.date,'%y/%m/%d %H')
                              AND d.user='4')
LEFT JOIN stats_clicks AS c on(DATE_FORMAT(c.date,'%y/%m/%d %H') = DATE_FORMAT(stats_visits.date,'%y/%m/%d %H')
                           AND c.user='4')
WHERE DATE(stats_visits.date) = '2014-01-31'
  AND stats_visits.user = '4'
GROUP BY zdate
ORDER BY zdate ASC

它返回错误的'zrevenue'

enter image description here

如果我删除“SUM”,则会给出此响应:

enter image description here

它给出了一个“收入”,但在表格中有3行,其中'date'= 13,'revenue'= 0.85。

'zrevenue'应该是2.55,而不是10.200

“收入”是小数(8,2),表格是“InnoDB”

提前致谢!

0 个答案:

没有答案