标签:
--未旋转之前的查询结果 select s.Name ShiftName,h.BusinessEntityID,d.Name as DpartmentName from HumanResources.EmployeeDepartmentHistory h inner join HumanResources.Department d on h.DepartmentID=d.DepartmentID inner join HumanResources.Shift s on s.ShiftID=h.ShiftID WHERE ENDDATE IS NULL AND d.Name IN(‘Production‘,‘Engineering‘,‘Marketing‘) order by ShiftName
--旋转之后的结果 select ShiftName,Production,Engineering,Marketing from (select s.Name ShiftName,h.BusinessEntityID,d.Name as DpartmentName from HumanResources.EmployeeDepartmentHistory h inner join HumanResources.Department d on h.DepartmentID=d.DepartmentID inner join HumanResources.Shift s on s.ShiftID=h.ShiftID WHERE ENDDATE IS NULL AND d.Name IN(‘Production‘,‘Engineering‘,‘Marketing‘) )t pivot (count(BusinessEntityID) for DpartmentName in ([Production],[Engineering],[Marketing]))b order by ShiftName
标签:
原文地址:http://www.cnblogs.com/nzyjlr/p/5069711.html