简体   繁体   English

层次结构数据类型上的聚合

[英]Aggregation on Hierarchy Data types

I've been reading about the Hierarchy data type in MS SQL2012. 我一直在阅读有关MS SQL2012中的Hierarchy数据类型的信息。 I'm trying to store an organisation data structure with values at each level. 我正在尝试使用每个级别的值来存储组织数据结构。 I'm wondering how do you aggregate data that is associated to a Hierarchy data column. 我想知道如何聚合与层次结构数据列关联的数据。

for instance say I want to sum up everything to 3 levels from the top of the hierarchy, what would I use to do that. 例如,说我想将所有内容汇总到层次结构顶部的3个层次中,我将用它做什么。 What I use a group by or a roll-up or is there some new function I could use on the hierarchy data type. 我使用的分组方式或汇总方式,或者在层次结构数据类型上可以使用一些新功能。

To sum up everything up to 3 levels it looks like you could use GetLevel as per this link 总结所有内容到3个级别,您可以按照此链接使用GetLevel

http://technet.microsoft.com/en-us/3b4f7dae-65b5-4d8d-8641-87aba9aa692d http://msdn.microsoft.com/en-au/library/bb677197(v=sql.100).aspx http://technet.microsoft.com/zh-CN/3b4f7dae-65b5-4d8d-8641-87aba9aa692d http://msdn.microsoft.com/zh-CN/library/bb677197(v=sql.100).aspx

SELECT SUM(z)
FROM HumanResources.EmployeeOrg
WHERE OrgNode.GetLevel() BETWEEN 0 AND 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM