我正在尝试创建一个视图来报告过去24小时内哪些商店的价格发生了变化。在本报告中,我需要计算并显示商店,州,城市,地址和变更金额。
这是我到目前为止所尝试过的,但它没有正确比较商店及其价格。它比较了输出中另一家商店的价格。这是一个sqlite数据库,但最终会转移到MySql。
select
p_today.`url`,
p_today.`company`,
p_today.`state`,
p_today.`city`,
p_today.`location`,
p_today.`address`,
p_today.`timerecorded`,
p_yest.price as `yesterday`,
p_today.price as `today`,
p_yest.address,
p_yest.`timerecorded`,
(p_today.price - p_yest.price) as `change`
from
prices p_today
inner join prices p_yest on
p_today.address = p_yest.address
and date(p_today.`timerecorded`) > date(p_yest.`timerecorded`) + datetime('now')
and p_yest.price > 0
where p_today.price > 0
and date(p_today.`timerecorded`) = CURRENT_DATE
and change > 0.1
group by p_today.`address`
order by `change` desc