-2

enter image description here]

In the image, we have a table and we are supposed to use PIVOT functions in SQL to obtain the exact output shown below the original table. I have tried it but not able to get it. Can someone please help!!

GMB
  • 216,147
  • 25
  • 84
  • 135

1 Answers1

0

You can use conditional aggregation:

select name,
    max(case when grade = 1 then marks end) as grade1,
    max(case when grade = 2 then marks end) as grade2,
    max(case when grade = 3 then marks end) as grade3
from mytable
group by name
GMB
  • 216,147
  • 25
  • 84
  • 135