I’m trying to create a query that returns the closest (above) price for each id from table price for every date in table date.
date has these dates in it:
date
2010-11-25
2010-11-24
2010-11-10
price is as follows:
id date price
A 2010-11-26 24.99
A 2010-11-24 27.99
A 2010-11-13 22.12
B 2010-11-26 26.51
B 2010-11-24 23.24
B 2010-11-22 27.95
So for 2010-11-25 I should get
id date price
A 2010-11-26 24.99
B 2010-11-26 26.51
for 2010-11-10
id date price
A 2010-11-13 22.12
B 2010-11-22 27.95
for 2010-11-24
id date price
A 2010-11-24 27.99
B 2010-11-24 23.24
etc.
I believe getting the result for a given date is doable (maybe group by…having), however I am looking for a solution that does it for all the dates.
EDIT:
There was an error in the example, corrected…
I think you mean this, but there may be an error in your example. (Or misunderstand it).