I have a table in oracle which has missing data for a given id. I am trying to figure out the sql to fill in the data from start date: 01/01/2019 to end_dt: 10/1/2020. see the input data below. for status key the data can be filled based on its previous status key. see input:
expected output:
You can use a recursive query to generate the dates, then
cross join
that with the list of distinctid
s available in the table. Then, use window functions to bring the missing key values:You did not give a lot of details on how to bring the missing
status_key
s andprevious_status_key
s. Here is what the query does:status_key
is taken from the next non-null
previous_status_key
previous_status_key
is taken from the last non-null
status_key
, with a default of-1