Flat hierarchyid in SQL Server 2008
在SQL Server 2008中引入了hierarchyid来处理树状结构。下面简单就以AdventureWorks(无hierarchyid)和AdventureWorks2008(有hierarchyid)里的HumanResources.Employee为例,来说明一下在新的hierarchyid中如何进行flat化的dimension抽取。
AdventureWorks是微软为SQL Server提供的数据库虚拟案例。
AdventureWorks中所要的结果集代码如下:
select L4.NationalIDNumber, L4.Title, L3.NationalIDNumber, L3.Title, L2.NationalIDNumber, L2.Title, L1.NationalIDNumber, L1.Title, L0.NationalIDNumber, L0.Title
from HumanResources.Employee L4, HumanResources.Employee L3, HumanResources.Employee L2, HumanResources.Employee L1, HumanResources.Employee L0
where L4.ManagerID = L3.EmployeeID and L3.ManagerID = L2.EmployeeID and L2.ManagerID = L1.EmployeeID and L1.ManagerID = L0.EmployeeID
AdventureWorks2008中的代码如下:
select L4.NationalIDNumber, L4.JobTitle, L3.NationalIDNumber, L3.JobTitle, L2.NationalIDNumber, L2.JobTitle, L1.NationalIDNumber, L1.JobTitle, L0.NationalIDNumber, L0.JobTitle
from HumanResources.Employee L0, HumanResources.Employee L1, HumanResources.Employee L2, HumanResources.Employee L3, HumanResources.Employee L4
where L4.OrganizationNode.GetAncestor(1)=L3.OrganizationNode and L3.OrganizationNode.GetAncestor(1)=L2.OrganizationNode and L2.OrganizationNode.GetAncestor(1)=L1.OrganizationNode and L1.OrganizationNode.GetAncestor(1)=L0.OrganizationNode
GetAncestor()是HierarchyNode类里其中的一个方法。更多hierarchyid数据类型方法引用可参考以下链接:
http://technet.microsoft.com/zh-cn/library/bb677193.aspx
相关文档:
[MySQL优化] -- 如何了解SQL的执行频率
时间:2010-2-28来源:HaCMS开源社区 作者:chuxu
MySQL 客户端连接成功后,通过 show [session|global]status 命令 可以提供服务器状态信息,也可以在操作系统上使用 mysqladmin extended-status 命令获得这些消息。 show [session|global] status 可以根据需要加上参数&ldquo ......
--select name from sysobjects where type='U' order by name
SELECT
(case when a.colorder=1 then d.name else '' end) 表名,
-- a.colorder 字段序号,
a.name 字段名,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
(case when (SELECT count(* ......
SQLServer和Oracle的常用函数对比
1.绝对值
S:select abs(-1) value
O:select abs(-1) value from dual
2.取整(大)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.取整(小)
S:select floor(-1.001) value
O:select floor(-1.001) value fr ......
1.求1..10偶数之和
select sum(level) from dual
where mod(level,2)=0
connect by level
2.将update改换成用rowid来实现。
(1)新的写法:
merge into SNAPSHOT120_2010_572 t1
using (select a.rowid rid, b.vip_level, b.manager_name
from xyf_vip_info_new b, snapsho ......