I have a main table where all my results will be written to. Each object that will be checked is identified by the item_id:
Checkdate item_id Price Cat A Price Cat B
2017-04-25 1 29.99 84.99
2017-04-24 1 39.99 89.99
2017-04-23 1 39.99 91.99
2017-04-25 2 42.99 88.99
2017-04-23 2 41.99 81.99
2017-04-22 2 50.99 81.99
2017-04-21 2 42.99 81.99
In the postgres query i select all results with the current_date = checkdate to provide the newest data:
Item Price Cat A Price Cat B
1 29.99 84.99
2 42.99 88.99
So far its not a problem for me. But now i want to compare these results with the previous results. Something like that:
Item Price Cat A Price Cat A Before Price Cat B Price Cat B Before
1 29.99 39.99 84.99 89.99
2 42.99 41.99 88.99 81.99
But I have no idea how to do that. These items doesn't exist on every day (item 2 doesn't exist on 2017-04-24 for example).
Can someone help me?
current_date = checkdateseems to imply that you check all your (current) items every day. Is that so? Smells funny...