我有一个奇怪的问题,计算基于从今天的值中减去前一天的值
这是查询。示例数据和查询结果在这里
SELECT pd.id,pd.price_date,pd.name_id,pd.class_id,pd.currency_id,pd.price,
pd.price - (SELECT price
FROM price_data as x
WHERE x.price_date < pd.price_date
AND x.name_id = pd.name_id
AND x.class_id = pd.class_id
AND x.currency_id = pd.currency_id
HAVING MAX(x.price_date)) as `change`
FROM price_data as pd
WHERE pd.name_id ='BILL'
ORDER bY pd.name_id,pd.class_id,pd.currency_id,pd.price_date
如果您查看结果集,您会发现计算一直有效,直到它第一次在row 6
. 似乎开始将先前的更改添加到当前更改中。
日期确定有问题吗?