摘要:MS SQL 樞紐語法 PIVOT
因為之前有使用過PIVOT,現在又要用一次,但找不到原語法,所以紀錄一下語法
SELECT Column1,Column2,Column3,P1,P2,P3
FROM
(
select Column1,Column2,Column3
from dbo.Table1 with (nolock)
) AS SourceTable--來源資料
PIVOT
(
Max(YouWantTransColumnName)
FOR YouWantTransColumnName IN (P1,P2,P3)
) AS PivotTable;--樞紐欄位