Min and Max date for every change in value of a flag

Database

Min and Max date for every change in value of a flag

Hi All,

I have a dataset that looks like this:

ID        start_date    end_date       flag

12345  2014-06-04  2014-07-03    I

12345  2014-07-04  2014-08-14    O

12345  2014-07-04  2014-12-01    O

12345  2014-07-04   2015-03-01   O

12345 2015-03-02   2015-05-01    I

12345 2015-05-02    2899-12-31   I

And I want the output as

12345 2014-06-04  2014-07-03 I

12345 2014-07-04  2015-03-01 O

12345 2015-03-02  2899-12-31 I

Change between I and O can happen multiple times.

Hence I  cant use min max or QUALIFY directly.

Please let me know how can i solve this.

Thanks in Advance :)

Tags (3)
1 REPLY
Junior Contributor

Re: Min and Max date for every change in value of a flag