Skip to content
Advertisement

How to combine records start date and end date in SQL

I have a set of data example below:

ID Role START_DATE END_DATE
1 A 2022-02-01 2022-02-03
1 A 2022-02-03 2022-02-10
1 A 2022-02-10 9000-12-31
2 B 2022-02-01 2022-02-03
2 A 2022-02-03 2022-02-04
2 B 2022-02-04 2022-02-11

I want to group them based on the ID, ROLE, START_DATE and END_DATE. So it looks like below: x

ID Role START_DATE END_DATE
1 A 2022-02-01 9000-12-31
2 B 2022-02-01 2022-02-03
2 A 2022-02-03 2022-02-04
2 B 2022-02-04 2022-02-11

How can I achieve this?

Thanks

Advertisement

Answer

Simple task for Teradata’s NORMALIZE:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement