易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

SQL按照日、周、月、年统计数据

如: 表:consume_record 
字段:consume (money类型)  date (datetime类型) 
请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量. 
如:1月 1200元 
2月 3400元 
3月 2800元 
--按日 
select sum(consume),day([date]) from& ......

JSP连接SQL SERVER 2008 找不到驱动

哪位高手能帮我看下为什么抛出这些异常?
代码
<%@ page language="java" import="java.util.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="GB2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< ......

sql语句优化

SQL语句的优化就是将性能较低的SQL语句转换达成同样目的性能优异的SQL语句
下面我们一起来看看一些可以优化SQL的方法,希望大家多提出意见我们共同学习或者是大家有什么好的优化方法可以提出来共享一下。
第一种优化(使用指定列代替”*”)
       使用“*”可以降低编写SQL语 ......

好的SQL收集 不断更新中

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号