Original Table X as :
ID | START_DATE | END_DATE | GRP |
---|---|---|---|
001 | 2017-10-15 | 2018-10-21 | 1 |
001 | 2017-10-15 | 2019-10-21 | 0 |
001 | 2020-05-18 | 2021-05-03 | 1 |
select ID, start_date, end_date,
sum(grp) over(partition by ID order by start_date, end_date) as island
from X
```
In Teradata the result is:
| ID | START_DATE | END_DATE | island |
| -------- | ------------ | -------- |------- |
| 001 | 2017-10-15 |2018-10-21| 2 |
| 001 | 2017-10-15 |2019-10-21| 2 |
| 001 | 2020-05-18 |2021-05-03| 2 |
In Oracle and MySQL the results are:
| ID | START_DATE | END_DATE | island |
| -------- | ------------ | -------- |------- |
| 001 | 2017-10-15 |2018-10-21| 1 |
| 001 | 2017-10-15 |2019-10-21| 1 |
| 001 | 2020-05-18 |2021-05-03| 2 |
Any suggestions to fix the Teradata result? Many thanks !!