需要在 Oracle 分层查询中显示父级下子级下的孙级
我有一张表,其中有州、地区、地区、建筑物和班级的树。每行都有一个节点 ID 和一个父 ID。我正在使用
select name, child node, parent id from tableA
connect by prior child node = parent id
我得到的以下内容:
CA
CENTRAL REGION
FRESNO DISTRICT
ST Jim BUILDING
ST joe BUILDING
st tom BUILDING
st sue BUILDING
JIMS CLASS
JOES CLASS
TOM CLASS
SUE CLASS
问题是在建筑级别,所有建筑物都被一个接一个地列出,然后所有的类一个接一个地列出。但是,我想列出建筑物及其作为下一个建筑物的父级的类,如下所示,
FRESNO DISTRICT
st jim building
jims class
st joes building
joes class...
节点 id 和父级 id 是正确的,只是列出了父级的所有子级,然后列出了该子级的所有子级。它没有显示哪个孩子与父母一起去。
我想从上到下显示树,例如 CA、中部地区、弗雷斯诺区、圣乔大楼、Ms Mary 班、Ms
I have a table that has a tree of state, region, district, building and classes. Each row has a node id and a parent id. I am using the following
select name, child node, parent id from tableA
connect by prior child node = parent id
i get:
CA
CENTRAL REGION
FRESNO DISTRICT
ST Jim BUILDING
ST joe BUILDING
st tom BUILDING
st sue BUILDING
JIMS CLASS
JOES CLASS
TOM CLASS
SUE CLASS
Problem is that at building level all buildings are listed one after another and then all the classes one after another. However I want to list the building and the class it is a parent of then the next building as follows
FRESNO DISTRICT
st jim building
jims class
st joes building
joes class...
the node id and parent id are correct it just that all children are listed for a parent then all children for that child. it is not showing which child goes with the parent.
I want to show the tree from the top down such as CA, Central region, Fresno district, St Joe Building, Ms Mary class, Ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应保留分层顺序,除非您使用不带 SIBLINGS 关键字的 ORDER BY。
使用此数据:
The hierarchical ordering should be preserved, unless you use an ORDER BY without the SIBLINGS keyword.
Using this data: