-2

I would like to get the output for the over lapping date records

> Data: Id Open_date Closed_Date
>       1  2016-01-01 2017-01-01
**>       1  2016-12-31 2018-21-01
>       1  2016-01-01 2018-01-01**
>       2  2017-01-01 2018-02-02
Here, you see the second & 3rd records are starting with date than the closed_Date of their previous records. Here i need to identify those type of records
Hari
  • 1
  • 1

2 Answers2

0

As you question is not much clear, I am assuming that you are looking for min of open date and max of close date.
If this is not the requirement edit the question to provide more details.

select id, min(Open_date), max(Closed_Date)
from table
group by id
Gaurav
  • 1,070
  • 9
  • 11
0

Looks like you want to normalize a Slowly Changing Dimension Type 2. Of course the best way to handle them would be using Temporal tables using either Teradata or ANSI syntax.

There's a nice syntax in Teradata to get your expected result based on the Period data type, but it's imple to cast your begin/end dates to a period:

SELECT id,
   -- split the period back into seperate dates
   Begin(pd) AS Open_date,
   End(pd) AS Closed_Date
FROM
 (
   SELECT NORMALIZE -- magic keyword :-)
      id, PERIOD(Open_date, Closed_Date) AS pd
   FROM tab
 ) AS dt
dnoeth
  • 59,503
  • 4
  • 39
  • 56