我有以下 2 个查询,但它们返回不同的结果。例如,如果我从一个终端请求总金额,我得到:456。
如果我每隔 15 分钟问一次,把所有的值都加起来,我得到 474……这怎么可能?
我获取总金额的查询如下
SELECT SUM(logs.amount) * ei_relationships.itemprice as income
, currency
FROM ei_relationships
RIGHT OUTER JOIN logs ON ei_relationships.id = logs.ei_relationship_id
WHERE ei_relationships.event_id = 1
AND logs.serial = '5B:13:52:28:71:21:ED:F1'
ORDER BY currency, log_time ASC
这是我获取相同数据的查询,但现在将其划分为 15 分钟
SELECT SUM(logs.amount) * ei_relationships.itemprice as income
, UNIX_TIMESTAMP(log_time) - UNIX_TIMESTAMP(log_time)%(900) as hour
, currency
FROM ei_relationships
RIGHT OUTER JOIN logs ON ei_relationships.id = logs.ei_relationship_id
WHERE ei_relationships.event_id = 1
AND logs.serial = '5B:13:52:28:71:21:ED:F1'
GROUP BY hour
ORDER BY currency, log_time ASC