SQL unpivot example

SELECT [county] [CountyName],[Year],[FIPS], MillionGallon, Category
FROM [USGS].[APP].[CountyWater]
unpivot
(MillionGallon for Category in
([Aquaculture GroundWater] , [Aquaculture Surface Water],[Aquaculture Total],
[Domestic GroundWater],[Domestic Surface Water],[Domestic Total],
[Irrigation GroundWater] , [Irrigation Surface Water],[Irrigation Total],
[Industrial GroundWater],[Industrial Surface Water],[Industrial Total],
[Livestock GroundWater],[Livestock Surface Water],[Livestock Total],
[Mining GroundWater],[Mining Surface Water],[Mining Total],
[Thermoelectric GroundWater],[Thermoelectric Surface Water],[Thermoelectric Total],
[PublicSupply GroundWater],[PublicSupply Surface Water],[PublicSupply Total]
)
)as TableUnpivot

Leave a Reply

Your email address will not be published. Required fields are marked *