詳細請參考來源:Pivoting on multiple columns - SQL Server
---
SELECT
Seq,
ItemCode,
ItemModel,
ItemColour,
ItemName
FROM TblPivot
-- Applying pivoting on multiple columns
SELECT
*
FROM
(
SELECT
Seq,
ItemCode,
ItemModel,
ItemName,
ItemColour
FROM TblPivot
) AS P
-- For ItemColour
PIVOT
(
Count(ItemCode) FOR ItemColour IN ([Red], [Blue], [Green])
) AS pv1
-- For ItemName
PIVOT
(
Count(ItemModel) FOR ItemName IN ([Samsung Mobile], [Nokia Mobile], [Motorola Mobile])
) AS pv2
GO
沒有留言:
張貼留言