Unpivot with column name

前端 未结 4 2121
忘掉有多难
忘掉有多难 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:44

    Another way around using cross join would be to specify column names inside cross join

    select name, Subject, Marks 
    from studentmarks
    Cross Join (
    values (Maths,'Maths'),(Science,'Science'),(English,'English')
    ) un(Marks, Subject)
    where marks is not null;
    

提交回复
热议问题