易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

[MySQL优化] 如何了解SQL的执行频率


[MySQL优化] -- 如何了解SQL的执行频率
时间:2010-2-28来源:HaCMS开源社区 作者:chuxu
MySQL 客户端连接成功后,通过 show [session|global]status 命令 可以提供服务器状态信息,也可以在操作系统上使用 mysqladmin extended-status 命令获得这些消息。 show [session|global] status 可以根据需要加上参数&ldquo ......

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

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

【汇总】SQL CODE 经典·精彩

【汇总】SQL CODE --- 经典·精彩
数据操作类 SQLHelper.cs
无限级分类 存储过程
百万级分页存储
SQL经典短小代码收集
 
学生表 课程表 成绩表 教师表
50个常用sql语句
SQL SERVER
与ACCESS、EXCEL的数据转换
 
游标
根据不同的条件查询不同的表
INNER JOIN 语法
master.dbo.sp ......

SQL Select Into语句


SQL Select Into语句
The SELECT INTO Statement
SELECT INTO 语句
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTO语句常用来给数据表建立备份或是历史档案。
Syntax
语法
SELECT column_name(s) INTO newtable [IN externaldatabase] ......

好的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号