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
Ïà¹ØÎĵµ£º
Èç: ±í:consume_record
×Ö¶Î:consume (moneyÀàÐÍ) date (datetimeÀàÐÍ)
ÇëÎÊÔõôдËÄÌõsqlÓï¾ä·Ö±ð°´ÈÕ,°´ÖÜ,°´ÔÂ,°´¼¾Í³¼ÆÏû·Ñ×ÜÁ¿.
Èç:1ÔÂ 1200Ôª
2ÔÂ 3400Ôª
3ÔÂ 2800Ôª
--°´ÈÕ
select sum(consume),day([date]) from& ......
sql replace Ìæ»»×Ö¶ÎÖв¿·ÝÖ¸¶¨ÄÚÈÝ
´´½¨Êý¾Ý¿â½Ì³Ì
create database cnnet;
´´½¨Êý¾Ý±í
CREATE TABLE `cnnet`.`test` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`url` VARCHAR( 50 ) NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM
²å¼¸ÌõÊý¾Ý:
INSERT INTO `test` (`id`, `url`) VALUES
(1, 'www.1aa.cm' ......
1¡¢ ´ò¿ªpl/sql ÖÐtools-preferences£¬ÉèÖÃConnectionÖеÄOracle HomeΪoracle9£¬OCI libraryΪoracle9 Èçͼ
2¡¢
½«oralce10Ŀ¼ÏµÄtnsnames.oraÎļþÀïÃæµÄËùÒªµ¼³öµÄoralce10µÄ·þÎñÅäÖà ¸´ÖƵ½oracle9Ŀ¼ÏµÄtnsnames.oraÎļþÀïÃæ
ORCL =
(DESCRIP ......
ÎÊÌâ¼°ÃèÊö£º
--1.ѧÉú±í
Student(S#,Sname,Sage,Ssex) --S# ѧÉú±àºÅ,Sname ѧÉúÐÕÃû,Sage ³öÉúÄêÔÂ,Ssex ѧÉúÐÔ±ð
--2.¿Î³Ì±í
Course(C#,Cname,T#) --C# --¿Î³Ì±àºÅ,Cname ¿Î³ÌÃû³Æ,T# ½Ìʦ±àºÅ
--3.½Ìʦ±í
Teacher(T#,Tname) --T# ½Ìʦ±àºÅ,Tname ½ÌʦÐÕÃû
--4.³É¼¨±í
SC(S#,C#,score) --S# ѧÉú±àºÅ,C# ¿Î³Ì ......
µ±Ê¹ÓÃMicrosoft SQL Server 2008 Management Studioʱ£¬ÓÐʱÔÚ±íÉè¼ÆÆ÷ÖжԱíËù×öµÄ¸ü¸ÄÎÞ·¨±£´æ£¬¾ßÌå±íÏÖΪ£ºµã»÷±£´æ°´Å¥ºóµ¯³ö±£´æ¶Ô»°¿òÌáʾ£º²»ÔÊÐí±£´æÐÞ¸Ä(Saving changes is not permitted)£¬µ¯³öµÄ¶Ô»°¿òÖ»ÓÐ2¸ö°´Å¥¿ÉÒÔµã»÷£¬Ò»¸öCancelÒ»¸öSave Text File£¬Ç°Ò»¸ö¾Í²»ÓÃ˵ÁË£¬ºóÒ»¸ö±£´æµÄÎļþ¸ù±¾Ã»ÒâÒ壨¿ÉÒ ......