0

I have query which returns data in following format

QuestionID  MaxPoints  PointsAchived0 PointsAchieved1 PointsAchived2
Q1            2              208          102              100
Q2            1              218          192              N/A
Q3            1              190          220              N/A
Q4            2              50           120              240
Q5            2              20           270              120

i need output like

Label              Q1           Q2        Q3        Q4           Q5
MaxPoints          2            1         1         2            2
PointsAchived0     208          218       190       50           20
PointsAchived1     102          192       220       120          270
PointsAchived2     100          N/A       N/A       240          120

i have searched several topics all have aggregation function in the Pivot Syntax. how i achieve my requirement. also just to add questions count may vary depending on my conditions in query.

any help is appreciated.

Kaushal
  • 471
  • 3
  • 15
  • What database are you using? – Taryn Apr 06 '15 at 17:47
  • @Kaushal It would be useful if you post the query you're using to obtain the results you mentioned in the question, so we can extract additional details. – G21 Apr 06 '15 at 17:52
  • 1
    This is a full transpose of your table and this has been answered a few times on SO [example 1](http://stackoverflow.com/questions/15297809/sql-transpose-full-table) or [example 2](http://stackoverflow.com/questions/12696225/sql-real-transpose). Basically you need to unpivot your existing data into multiple rows and then pivot those results into your final product. – Taryn Apr 06 '15 at 17:52
  • thanks bluefeet for links of full transpose +1 for this – Kaushal Apr 06 '15 at 18:17

0 Answers0