Unpivot with column name

前端 未结 4 2171
忘掉有多难
忘掉有多难 2020-11-22 06:10

I have a table StudentMarks with columns Name, Maths, Science, English. Data is like

Name,  Maths, Science, English  
Tilak, 90         


        
4条回答
  •  眼角桃花
    2020-11-22 06:51

    Your query is very close. You should be able to use the following which includes the subject in the final select list:

    select u.name, u.subject, u.marks
    from student s
    unpivot
    (
      marks
      for subject in (Maths, Science, English)
    ) u;
    

    See SQL Fiddle with demo

提交回复
热议问题