【发布时间】:2011-05-25 09:35:54
【问题描述】:
我需要从单个表中返回树状结果。目前我使用 connect by 和 start with 以确保返回所有正确的结果。
select id,parent_id
from myTable
connect by prior id = parent_id start with name = 'manager'
group by id, parent_id
order by parent_id asc
但是我希望结果以树结构返回。因此,每次找到父行时,其子行将直接显示在其下方。然后移动到下一个父母并做同样的事情
预期结果
- Parent A
- child a
- child b
- Parent B
- child c
- child d
实际结果
- Parent A
- Parent B
- child a
- child b
- child c
- child d
在 oracle 中可以做到这一点吗?我的表使用 parent_id 字段来识别行何时有父级。每行也有一个排序顺序,这是它应该在其父级下排序的顺序和一个唯一的 Id。
我正在使用 Oracle 数据库
【问题讨论】: