Oracle query to Get data in separate columns based on condition

I have table like below.

enter image description here like below

the result I need is IN and OUT in different columns as shown in RESULT table. If the first entry for a particular vehicle is IN then I need the immediate OUT else keep it blank.
But if the first record for a particular vehicle is OUT then I need to get the last IN record for that vehicle for the previous date,if exists any(example in the fig for veh2).

Is there a way to do it using oracle query? Can anyone help me in anyway doing this?Thanks in advance.

Source: oracle

Leave a Reply