I need to select an entity that is valid at the midth of the validity of different entity.
As a simplified example, I want to do something like this:
select
*
from
o1, o2
where
o1.from < (o2.to - ((o2.to - o2.from) /2) )
and
o1.to > (o2.to - ((o2.to - o2.from) /2) )
How can I compute “(o2.to – ((o2.to – o2.from) /2) )” in SQL, assuming that to and from are timestamps?
Did you try what you have written? It looks like it should work to me:
This will give you a partial day difference, eg:
Then if you add that result to the original date, you will get the date and time at the midpoint: