select PurchaseOrderID
, [244,231] as FirstEmp
, [266,274] as secondEmp
, [231,241] as ThirdEmp
from ( select PurchaseOrderID, EmployeeID, TaxAmt
from Purchasing.PurchaseOrderHeader
Where EmployeeID IN (244, 231, 266, 274, 241)
) SourceTable
PIVOT (
SUM(TaxAmt)
FOR EmployeeID IN([244,231],[266,274],[231,241])
) AS PVT
从上面的查询中,我必须使用 pivot 检索特定 GLcode 组的数据。
我需要一个类似下面的结果,这意味着SUM(TaxAmt)
一个组GLCode IN (244,231)
和另一个第二个 ForGLCode IN (266,274)
和第三个 is GLCode IN (231,241)
。
---------------------------------------------------------
PurchaseOrderID [244,231] [266,274] [231,241]
---------------------------------------------------------
1 5678 10456 45643
2 3456 5643 564
3 34567 5678 4243
4 5897 65645 7567
---------------------------------------------------------------