I have a table with internal_id, states, start time and end time. I am trying to overlay the recent state to the previous states and return the value.
I have a simple working example here which works fine for the initial case. It overlay recent data, i.e id=5 over id=4 .
But when I add a new row -
(5, 1, 'Simba', '2022-01-01 00:00:00', '2022-01-04 00:00:00');
I am expecting this new row to overlay over all records and only show this row as result. Recent (higher ID) should have the precedence over lower id's. This is shown in example 1. I can also have other cases where 'Simba' can be of shorter duration and overlay should be something like example 2.
Example 1
=====S=======================
=A== ====G====
====B====
---------------------------------------
============S===============
Example 2
==S=================================
=A== ====G====
====B====
----------------------------------------
=A=|======S========|===B====|==S=======
I feel I am doing something wrong and might be using recursion but not sure. Can someone please point what I might be missing?
[)
instead of[]
?