I have a table with indexes of imported files, with dates and branches of each imported files.
Now I need to do a consolidation of multiple branches, so, that I have to duplicate the information from some branches when we have holidays, so that the data is consistent, basically I need to fill these gaps with the latest available information.
I tried doing some self-joins with ranking in order to shift between them and get the previous data, but it didn't work.
What I have is a table:
rundate, branch, imported
2015-04-01, PL1, TRUE
2015-04-01, ES1, TRUE
2015-04-01, CZ4, TRUE
2015-04-02, PL1, TRUE
2015-04-02, ES1, TRUE
2015-04-02, CZ4, TRUE
2015-04-03, ES1, TRUE
2015-04-03, CZ4, TRUE
In this example, I would like to make a query that returns:
gap_date, branch, real_date
2015-04-03, PL1, 2015-04-02
This table is quite small (couple thousand lines), so, performance shouldn't be a big issue.
Any idea on how can I achieve that?
Now I am using a function that receives the rundate and branch of the gap dates as parameters, and answers the latest before the date passed as parameter (using max(rundate) where rundate <= '$1')
Thanks!