【发布时间】:2014-03-19 07:03:22
【问题描述】:
我最近下载了适用于 SQL Server Management Studio 的 AdventureWorks2012,并在网上找到了一些关于数据库的问题。我真的被困在其中,迫切需要一些指导;
展示从 Ruth Ellerbrock 到 CEO Ken Sanchez 的管理层次结构
组织中的每个人在层次结构中都有一个OrganizationalLevel; CEO0,副总裁1,工程经理2,高级工具设计师3,逐渐走下坡路。最低的是 4。
我在做什么:我将[Person].[Person] 和[HumanResources].[Employee] 两个表连接在一起以获得FirstName, LastName,JobTitle, OrganizationalLevel
Select [Person].[Person].FirstName
, [Person].[Person].LastName
, [HumanResources].[Employee].OrganizationLevel
from [HumanResources].[Employee]
JOIN person.person ON ([HumanResources].[Employee].[BusinessEntityID]=[Person].[Person].[BusinessEntityID])
我的理解是我需要使用递归查询或公用表表达式,但我真的不知道如何。
任何帮助将不胜感激。如有任何问题,请随时提出更多详细信息。
谢谢。
【问题讨论】:
-
哪个字段表示谁管理谁或谁由谁管理?
标签: sql recursion sql-server-2012 common-table-expression adventureworks