Oracle SQL左连接同一表的次数未知

Oracle SQL左连接同一表的次数未知,第1张

Oracle SQL左连接同一表的次数未知

您正在寻找的是一个递归查询。像这样的东西:

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
old
Oracle的
KEEP LAST

Rextester演示:http
://rextester.com/CHTG34988



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5675282.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存