Thanks all, I have been proved wrong by the amazing power of OLAP and
Birgitta's query works perfectly.
- *Subject*: RE: Tricky SQL extraction question
- *From*: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
- *Date*: Wed, 20 Dec 2023 19:32:52 +0100
------------------------------
Your could try something like this:
With x as (Select Row_Number() Over(Partition By Client Order By StartDate)
Lfd,
a.*
from MyTable a)
Select *
from x join x y on x.Client = y.Client and x.lfd = y.lfd-1
Where x.EndDate > y.StartDate
or x.EndDate <> y.StartDate - 1 Day;
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
Modernization ? Education ? Consulting on IBM i
Database and Software Architect
IBM Champion since 2020
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
"Train people well enough so they can leave, treat them well enough so they
don't want to. " (Richard Branson)
"Learning is experience ? everything else is only information!" (Albert
Einstein)
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Dave
Sent: Wednesday, 20 December 2023 18:27
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Tricky SQL extraction question
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!
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.
On Wed, 20 Dec 2023 at 18:26, Dave <dfx1@xxxxxxxxxxxxxx> wrote:
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.