select e.ename,e.sal,
coalesce(
(select min(sal) from emp d where d.sal>e.sal),
(select min(sal) from emp)
) as forware,
coalesce(
(select max(sal) from emp d where d.sal<e.sal),
(select max(sal) from emp)
) as rewind
from emp e
order by 2;
select e.ename,e.sal,
coalesce(
(select min(sal) from emp d where d.sal>e.sal),
(select min(sal) from emp)
) as forware,
coalesce(
(select max(sal) from emp d where d.sal<e.sal),
(select max(sal) from emp)
) as rewind
from emp e
order by 2;