U kunt dit doen met row_number()
en doe zelf mee:
select e1.empid as empid_1, e2.empid as empid_2
from (select e.*, row_number() over (order by emp_id) as seqnum
from emp e
) e1 join
(select e.*, row_number() over (order by emp_id desc) as seqnum
from emp e
) e2
on e1.seqnum = e2.seqnum;
BEWERKEN:
Je zou dit ook kunnen doen met rownum
maar het vereist een extra select
:
select e1.empid as empid_1, e2.empid as empid_2
from (select e.*, rownum as seqnum
from (select e.* from emp e order by empid asc) e
) e1 join
(select e.*, rownum as seqnum
from (select e.* from emp e order by empid desc) e
) e2
on e1.seqnum = e2.seqnum;