多父级递归
Master Table
===========
ID NAME
1 A
2 B
3 C
4 D
5 E
具有多个父级的层次结构表(请注意,由于重复值,两者都不能成为主列):
Relations Table
================
ChildID ParentID
3 1
3 2
4 3
4 2
5 4
层次结构变得像(它可能并不总是这样线性):
1 2
| |
3 3
| |
4 4
| |
5 5
出于报告目的,我需要递归层次结构格式的数据,以便我可以深入了解它。我不知道是否可以从现有数据本身获取向下钻取功能(似乎不可行,因为由于重复值,我无法创建递归父子关系)。
你有什么想法吗?我的目标是最终使用这个结构作为 SSAS 中的一个维度,如果表具有自主键-子键关系,它会自动提供向下钻取。
Master Table
===========
ID NAME
1 A
2 B
3 C
4 D
5 E
Hierarchy table with multiple parents (Note that neither can be primary column due to duplicate values):
Relations Table
================
ChildID ParentID
3 1
3 2
4 3
4 2
5 4
Hierarchy becomes like (it might not be this linear always):
1 2
| |
3 3
| |
4 4
| |
5 5
For reporting purpose I need data in recursive hierarchy format so that I can drill down it. I'm not getting if I can get drill down feature from existing data itself (seems not doable as I can not create recursive parent-child relationship due to duplicate values).
Do you have any ideas? My goal is to finally use this structure as a dimension in SSAS which automatically gives drill down if a table has a self primary key-child key relationship.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您的示例数据,我实际上得到了一棵不同的树...
您实际上想要两棵独立的树吗?如果是这种情况,您可以引入一个额外的字段,例如树 id...
如果没有一些额外的信息,您将始终遇到分支分裂和合并的问题,而没有一组非常好的约束。例如,如果您想要 1-3-4-5 和 2-3-4-6 的两个线性树,您当前的模型将具有此...
但您现在遇到的问题是有四个线性路径。 ..
- 1-3-4-5
- 1-3-4-6
- 2-3-4-5
- 2-3-4-6
您可能需要描述一个现实世界的情况,准确地描述您想要从中得到什么,以及准确地描述您不想要从中得到什么。
我的典型经验是,出于报告目的,树中的任何节点都应该只有一个父节点,但可能有许多子节点。这意味着当爬上一棵树时,你只有一条路线,而当爬下一棵树时,数据会分成子节点。
有许多父母和许多孩子会形成一张网,而不是一棵树。无论您从哪个方向遍历树,都有多条路线。
Using your example data, I actually get a different tree...
Do you actually want two independent trees? If that's the case, you could introduce an extra field such as a tree id...
Without some extra piece of information, you'll always have problems of branches splitting and merging without a very well formed set of constraints. For example, if you wanted two linear trees of 1-3-4-5 and 2-3-4-6, your current model would have this...
The problem you now have though, is that there are FOUR linear paths...
- 1-3-4-5
- 1-3-4-6
- 2-3-4-5
- 2-3-4-6
What may be required is for you to describe a real world situation, exactly what you want from it, and exactly what you don't want from it.
My typical experience is that, for reporting purposes, any node in a tree should only have one parent, but may have many children. This means that when climbing up a tree you only have one route, and when climbing down a tree the data separates into sub-nodes.
Having many parents and many children makes a web rather than a tree. Where you have multiple routes, no matter which direction you traverse the tree.