Overlapping data handling in SQL

Database

Overlapping data handling in SQL

Hi All,

My requirement is as below.

I am having data as below in one of my table 

key1 key2 amt start_dt end_dt

1      11     10  2015-01-01 2015-01-14

1      11     10  2015-01-15 2015-01-31

1      11     10  2015-02-01 2015-02-15

1      11     15 2015-02-16  2015-02-25

1      11     10 2015-02-26 2015-03-15

My required o/p is 

key1 key2 amt start_dt end_dt

1      11     10  2015-01-01 2015-02-15

1      11     15 2015-02-16  2015-02-25

1      11     10 2015-02-26  2015-03-15

Basically first three records are merged into one single record with min start_dt and Highest end_dt 

and rest of the two records remain as it is.

I tried this using window function but when I  key column as key1 ,key2,amt with order by start_dt desc

the first three and last records forms a partition, which I don't want.

Is there are any other functionality to handle partitioning in an particular order

Tags (1)
1 REPLY
Enthusiast

Re: Overlapping data handling in SQL

This is a repetiti ve question over the forum.

Chck this out this will help

http://forums.teradata.com/forum/database/generating-rank-value-for-each-set-of-flags