× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi - here's a possible - I assume EndDate is null, then I replace it with a max value for a date.


Ranges do not overlap if start of one is on or after end of the other.


S1 > e2 or S2 > e1


To get overlaps, negate that relation, which is an and of the opposites -


s1 <= e2 and s2 <= e1


Here's one way to do that =


with cl1 as (select * from overlap),
cl2 as (select client, startdate, coalesce(enddate, '9999-12-31', enddate) enddate from overlap)
select distinct cl1.client from cl1 join cl2 on cl1.startdate <= cl2.enddate and cl2.startdate <= cl1.enddate;


I get C2, C3, and C4 - this definition of overlap kind of gets to be a 2-way thing - if 4 overlaps 2, 2 also overlaps 4.


There's probably more to get one side of the dupes - xy's approach might do it. This is based, though, on something I found by googling for the thing you want to do.


Cheers
Vern


On Wed, 20 Dec, 2023 at 11:27 AM, Dave <dfx1@xxxxxxxxxxxxxx<mailto:dfx1@xxxxxxxxxxxxxx>> wrote:


To: midrange systems technical discussion

Hi,

I never thought I would need to make a request and SQL could not help
me, but I can't see how I could use it here.
Any ideas how I can accomplish this? In the exemple, I need to extract
clients C3 and C4. C3 because one of the periods overlap; C4 because the
2nd period does not immediately follow the 1st one.

Client StartDate EndDate
C1 2023-05-31
C2 2023-01-01 2023-04-15
C2 2023-04-16 2023-12-31
C3 2023-02-28 2023-06-01
C3 2023-04-01
C4 2023-10-11 2023-11-13
C4 2023-11-15

Thanks!

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.