with cte (old, new, lev) as( select old, new, 1 as lev from mytable union all select m.old, cte.new, cte.lev + 1 from mytable m join cte on cte.old = m.new)select old, max(new) keep (dense_rank last order by lev) as newfrom ctegroup by oldorder by old;
递归CTE创建所有迭代(您可以通过将查询替换为来查看此迭代
select * fromcte)。而在最终的查询,我们得到最后的
new每
oldOracle的
KEEP LAST。
Rextester演示:http
://rextester.com/CHTG34988
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)