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
Dalla query precedente devo recuperare i dati per particolare gruppo di codici GL utilizzando pivot.ha bisogno di una soluzione per sql query using pivot
devo serve un risultato come il seguente, che significa SUM(TaxAmt)
per un gruppo GLCode IN (244,231)
e due secondi Per GLCode IN (266,274)
e terzo è 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
---------------------------------------------------------------
Cosa RDBMS? SQL non è abbastanza informazioni. Sto indovinando Oracle o SQL-Server a causa del 'pivot'? – Ben
@Ben Secondo la sintassi il suo MSSQL –
@ vimal quindi qual è la tua domanda? –