|
with tb as
(select 3 id, null relation, '张三' name, 800 sal
from dual
union all
select 1 id, 3 relation, 'jack', 700 sal
from dual
union all
select 4 id, null relation, '李四', 800 sal
from dual
union all
select 2 id, 4 relation, ' shisi', 900 sal
from dual)
select id,name,relation,sal from (
select t1.id,
t1.name,
t1.relation,
t1.sal,
case
when exists (select 1
from tb
where tb.id = t1.relation
start with relation is null
connect by prior id = relation
) then lag(t1.sal)over(order by rownum) end new_sal
from tb t1)
where sal>new_sal
c:\users\administrator\桌面\20161007 |
|