Find out that two segments intersecting or not
Lets say you got two segments (dates or other ranges) and want to find out are they intersecting each over:
a1|-----------|a2
b1|-----------|b2
Or maybe one including another:
a1|-------------------|a2
b1|----|b2
In that case you can use simple expression instead of tons of if
's or case
's:
not if(a1 < b1, a2 < b1, b2 < a1)
Or generic SQL version:
not (case (a1 < b1) when 1 then a2 < b1 else b2 < a1 end)
Searching for 'formula':
Written by Eugeniy Belyaev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#