层次问题
我有一个带有 hierarchyid 列的表。就像:
[NAME] [PATH]
Ahmet /
Aliye /1/
Selen /1/1/
Erdem /2/
Bilge /2/1/
Aydin /2/2/
Tomrs /2/2/2/
我想看到类似的名字:
[NAMES_WITH_HIERARCHY]
Ahmet
Ahmet/Aliye
Ahmet/Aliye/Selen
Ahmet/Erdem
Ahmet/Erdem/Bilge
Ahmet/Erdem/Aydin
Ahmet/Erdem/Aydin/Tomrs
我该怎么做?
I have a table with hierarchyid column. It is like:
[NAME] [PATH]
Ahmet /
Aliye /1/
Selen /1/1/
Erdem /2/
Bilge /2/1/
Aydin /2/2/
Tomrs /2/2/2/
I want to see NAMES like:
[NAMES_WITH_HIERARCHY]
Ahmet
Ahmet/Aliye
Ahmet/Aliye/Selen
Ahmet/Erdem
Ahmet/Erdem/Bilge
Ahmet/Erdem/Aydin
Ahmet/Erdem/Aydin/Tomrs
How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给你:
输出:
Here you go:
Output:
这个答案也帮助了我。我想我会添加它发现的改进。
将性能从 3 分钟更改
为
2 秒,无论索引如何,这都使其与自引用相当。
This answer helped me out too. Thought I would add an improvement it found.
Changing
to
increased performance from 3 min to 2 sec, this put it on par with self-referencing regardless of indexing.
您不必使用递归 CTE (Denis Valeev) 的答案,它的性能较低。只需将其与自己连接
即可输出:
You don't have to use recursive CTE (Denis Valeev)'s Answer, it has low performance. Just join it with herself
Output :