I’m using SQL Developer for Oracle 11g..
I need to be able to loop through a set of dates,
check to see if the END_DATE above or below is = or < or > than the next END_DATE
AND where the START_DATE is different..
Then assign a trip number that is the same as the one its = to or
assign a new trip number and then begin a new trip and check again
the next SET of dates to see if its = or < or > than the current date..
I think in order to do this I need to use the pl/sql cursor for loop..
I’ve tried to figure it out but its not making much sense to me..
For example, I want the end result to be something like this..
ROWID START_DATE END_DATE TRIP
1 30-DEC-11 1-Jan-12 1
2 31-DEC-11 2-Jan-12 2
3 31-DEC-11 2-Jan-12 2
4 01-JAN-12 3-Jan-12 3
5 03-JAN-12 4-Jan-12 4
6 01-JAN-12 1-Jan-12 5
7 02-JAN-12 4-Jan-12 6
Thanks in advance for your help.
Alex
Based on the data that you have, you simply want to enumerate the pairs of dates. You can also do this with dense_rank():
For your data, this will change the ordering. If you want to keep roughly the same ordering, then aggregate first, get the min row id, and do a dense_rank() or row_number(), and join back in the original data: