0

I have a table, like the below, and want to pivot year field and have the other field names (Units/AVGs) show up as row values

Units   AVGs    Year
---------------------
3       3.667   2015
2       7.000   2016
1       15.000  2017

Convert to something like the below

       2015    2016   2017 
---------------------------- 
Units  3       2      1
AVGs   3.667   7.000  15.000

I'm sure there is simple solution to this (using pivots) but the suggested solutions only pivot one field (e.g. Units) for another field (e.g. Year).

Tekca
  • 43
  • 1
  • 7
  • Yes, that is a pivot. actually, you need a dynamic pivot unless you know in advance how many years you are dealing with. – Zohar Peled Mar 14 '18 at 21:10
  • Possible duplicate of [Convert Rows to columns using 'Pivot' in SQL Server](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – RoMEoMusTDiE Mar 14 '18 at 21:16
  • @maSTAShuFu that example pivots "Count" for multiple weeks. I am looking at pivoting more than one value (Units, AVGs) for multiple "years". – Tekca Mar 15 '18 at 11:58
  • I can possibly pivot "Units" for "Years" and another pivot (AVGs) for "Years" and do a UNION - but there must be a better, cleaner way of doing this – Tekca Mar 15 '18 at 12:08

0 Answers0