Basically, I'm working with data from icu patients and studying a particular disease. For every patient, I have the disease stage during all of the patient's stay in the ICU, as you can see here:
The other table I have it's the records table:
I simply want to add to the records table the stage of the disease when that measure was made, which can be made simply by records.charttime BETWEEN timeline.starts AND timeline.ends
, but I want to do it in the most optimized way possible due to the records table having nearly 100 million rows, and the timeline table over 100k rows.
I read about the usage of CURSOR
, but I don't know if it makes sense using CURSOR
in this case, or maybe I'm just adding complexity and it can be solved easily using JOIN
.
What's the best solution?