What i'm trying to do is to find every MILES_INDICATOR that equals '4' and then, it will take the LOCATION_ID of the same row as the FROM value, then take the LOCATION_ID of the following row as the TO value.
The data must be sorted as : ORDER BY LOAD_ID, STOP_NUM.
How can i do that?
In the attachment, you will see 2 sheets:
1- Table extract = an example of the data in the table: LOAD_STOP
2- Final result = what i would like to see as the final result from the query
This should do it without having to join the table to itself. Should perform much better and should handle cases where there are gaps in the STOP_NUM field.
SELECT * FROM (SELECT load_id, stop_num, location_id "FROM", miles, miles_indicator, Lead(location_id) over ( PARTITION BY load_id ORDER BY stop_num) "TO" FROM load_stop WHERE open_time > Trunc(SYSDATE) - 7) WHERE miles_indicator = 4 ORDER BY load_id, stop_num;
There is no OPEN_TIME field in the sample data that you supplied, so I assume it is in that table. Also, removed the unnecessary conversions on SYSDATE.
There are also syntax errors in the accepted answer. The ORDER BY has ambiguous column names. They need to be prefixed with the correct table alias.
This post first appeared at Oracleinaction (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself).
I will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.