I'm using teradata. I have a table with two date columns and a product code. Like so
Prod ID StartDate EndDate
123 1-1-2013 1-5-2013
123 1-3-2013 1-10-2013
123 1-4-2013 1-10-2013
321 1-4-2013 1-10-2013
321 1-6-2013 1-12-2013
321 1-5-2013 1-12-2013
I need to write a query which will give me the minimum start date of the following 'end date' for the same product. So in the above example, the first product would return '1-3-2013', and for the second product I would receive '1-5-2013' cause the next end date '1-12-2013 is a duplicate, and I just need to get the minimum instance of it's 'start date'.
I have a feeling it's something like
min(startDate) over (partition by prodID order by endDate rows between 1 following and 1 following)
However, I feel I need a qualify statement in here which will make sure that the startDate of the next row is greater than the endDate of the current row.