  select a.agencyID,
    max( decode( a.v_number, '01', a.v_direction, null)) as V1,
    max( decode( a.v_number, '02', a.agnecyID, null)) as V2,
    a.v_direction
  from
    ( select
      a.agencyID,
      a.v_number,
      row_number()
      OVER( partition by a.agencyID, a.v_number order by a.v_direction)
      as row_num 
      a.v_direction
      from 
        -- ONLY VEHICLES 01 AND 02
        ( select avl.acdyear_number as agencyID,
            avl.unit_nbr as v_number,
            avl.vehicle_direction as v_direction
           from n46jad.acdu_vehicles_loc avl
           where avl.unit_nbr = '01' or avl.unit_nbr = '02'
           order by avl.acdyear_number, avl.unit_nbr
        ) 
    ) a
group by a.agencyID, row_num
order by a.agencyID, row_num;
    
