I’m trying to solve an SQL problem (even don’t know if this is possible or not).
Let me try to explain.
We want to transpose “range” of records based on date (interval) in one table to another table where this range will be kept as FROM/TO structure.
As example, we have the following starting table structure:
ID DATE
100 11-08-2012
100 12-08-2012
100 13-08-2012
100 17-08-2012
100 18-08-2012
101 01-09-2012
...
and we want the following table as result:
ID FROM_DATE TO_DATE
100 11-08-2012 13-08-2012
100 17-08-2012 18-08-2012
...
Intervals are kept in FROM/TO fields and in the case of a single date interval, the same date is kept in both fields.
Is there any way to do this using SQL?
I don’t think this would be possible directly in a query.You’ll need to write some code in a high level language or write a procedure for it.
In that case, you’ll need to simply get the rows of particular ID, order them by the date(?) and get the first and last row of the result. You can now populate the
FROM_DATEandTO_DATEusing this logic.