I am very new to SQL.
I have a table like this:
ID | TeamID | UserID | ElementID | PhaseID | Effort -------------------------------------------------
SELECT , [first pivoted column] AS , [second pivoted column] AS , ... [last pivoted column] AS FROM () AS PIVOT ( () FOR [] IN ( [first pivoted column], [second pivoted column], ... [last pivoted column]) ) AS ; USE AdventureWorks2008R2 ; GO SELECT DaysToManufacture, AVG(StandardCost) AS AverageCost FROM Production.Product GROUP BY DaysToManufacture; DaysToManufacture AverageCost 0 5.0885 1 223.88 2 359.1082 4 949.4105 -- 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; Here is the result set. Cost_Sorted_By_Production_Days 0 1 2 3 4 AverageCost 5.0885 223.88 359.1082 NULL 949.4105