递归SQL和不同级别的信息 [英] Recursive SQL and information on different level
问题描述
是否可以在同一查询中显示有关不同递归级别的信息?
Is it possible to display, in the same query, information concerning different level of recursivity ?
select LEVEL, ae2.CAB, ae2.NIVEAU, ae2.ENTITE, ae2.ENTITE_PARENT, ae2.libelle
from my_table ae2
where ae2.NIVEAU = 2
start with ae2.cab = 'XXX'
connect by prior ae2.entite_parent = ae2.entite
通过该查询,我(假设)具有关于根'XXX'上方的实体的4个级别的信息
With this query I have (let's say) 4 levels of information about the entity above root 'XXX'
是否可以同时显示根信息?
Is it possible to display root information at the same time?
推荐答案
Yes, it's possible to use the CONNECT_BY_ROOT operator. For instance, if you wanted the cab
of the parent your query would be:
select connect_by_root cab
, level, cab, niveau, entite, entite_parent, libelle
from my_table
where niveau = 2
start with cab = 'XXX'
connect by prior entite_parent = entite
您必须为要选择的每一列使用一个新的运算符.您不会使用此运算符从不同的"递归级别获取信息,而仅从根目录获取信息.如果您想要更多,则必须使用递归子查询分解.
You have to use a new operator for each column you want to select. You won't get information from a "different" level of recursivity using this operator, only from the root. If you want more you'll have to use recursive subquery factoring.
这篇关于递归SQL和不同级别的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!