group data by ranges

Analytics
Fan

group data by ranges

Hi

I'm new to this but i need to make this:

I have the following values

    id    val    date_from    date_to

1    1    0    1/4/2011    1/4/2011

2    1    0    1/1/2011    1/1/2011

3    1    0    1/5/2011    1/9/2011

4    1    0    12/31/2010    12/31/2010

5    1    0    1/2/2011    1/2/2011

6    1    1    1/3/2011    1/3/2011

7    2    3    1/6/2011    1/10/2011

8    2    3    1/1/2011    1/1/2011

9    3    4    1/1/2011    1/1/2011

I should obtain

id    val    date_from    date_to

1     0       12/31/2010   1/2/2011

1     0       1/4/2011       1/9/2011

2     3      1/1/2011        1/1/2011

2     3       1/6/2011    1/10/2011

1    1    1/3/2011    1/3/2011

....

So i need to group the data with the same id, val where the dates overlap and obtain the min from date_from and max from date_to withn the overlapped group. sorry if i didn't explain very well.

Thank you

2 REPLIES
Supporter

Re: group data by ranges

Re: group data by ranges

I read the post on "date gap analysis" but I have no clue how to begin to write it. I am new to Teradata and would really appreciate some help on writing the query that will consolidate consecutive and overlapping date spans into one span....Need help very bad.

Thank you so much

John