Hello,
Can u please send me a link or example of PIVOT table?
I am new in Sql-Server 2005.
Thanks & Regards,
Jitnedra
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manikavelu VelayuthamPosted Sep 13, 2010, 4:24 AM
GO
SELECT DaysToManufacture, AVG(StandardCost) AS AverageCost
FROM Production.Product
GROUP BY DaysToManufacture;
Result set of above query
DaysToManufacture AverageCost
0 5.0885
1 223.88
2 359.1082
4 949.4105
Pivot Query for above result set
-- Pivot table with one row and five columns
SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days,
[0], [1], [2], [3], [4]
FROM
(SELECT DaysToManufacture, StandardCost
FROM Production.Product) AS SourceTable
PIVOT
(
AVG(StandardCost)
FOR DaysToManufacture IN ([0], [1], [2], [3], [4])
) AS PivotTable;
Pivot Result of above Result Set
Cost_Sorted_By_Production_Days 0 1 2 3 4
AverageCost 5.0885 223.88 359.1082 NULL 949.4105