分层SQL问题 [英] Hierarchical SQL question
本文介绍了分层SQL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本的实体树结构.该树最多可以有5个节点深,但可以有N个节点宽.我已将这种关系映射到类似于以下所示的表中:
I have a basic tree structure of entities. The tree can be a maximum of 5 nodes deep, but may be N nodes wide. I have mapped this relationship in table similar to what is shown below:
myID | myDescription | myParentID
我从一个已知的对象开始,这可以转换为具有起始的"myID".现在,我想获取所有子节点.有没有一种方法可以在一条语句中获得所有子节点?这需要包括我的孩子们的孩子,然后沿着树走下去.我正在使用Oracle SQL.
I am starting out with a known object, which could translate to having a starting "myID". Now I want to get all the child nodes. Is there a way of getting all the child nodes in one statement? This needs to include the children of my children, and going on down the tree. I am using Oracle SQL.
谢谢, 杰伊
推荐答案
SELECT *
FROM mytable
START WITH
myid = :id
CONNECT BY
myparentid = PRIOR myid
这篇关于分层SQL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文