Avatar of tonMachine100
tonMachine100

asked on 

Compare date ranges between tables

Please see the attached.  Fig. 1 lists the raw data (two tables). Fig. 2 Shows the desired output.
Id like the output to merge the tables together, displaying the clients earliest start date and latest end date of overlapping date ranges. Note that all Episodes will always have an end date of 01-04-2008 or before. If the end date of the Episode is the same date or a day before the start date of the plan I want these date ranges merged. If there is a gap of more than one day I want this to count as two date ranges.
The tables are joined using the clientid fields. The start and end dates of a clients episode do not overlap, nor do the start and end dates of a clients plans.
Any help is appreciated!

Date-Range-Sample.xls
Oracle DatabaseSQL

Avatar of undefined
Last Comment
DrSQL - Scott Anderson

8/22/2022 - Mon