Sql行转列

  

1.把表一转换为表二

表一:  

表一

 

表二:

 

sql语句:

select stdname,
 isnull(sum(case stdsubject when '化学' then Result end),0) [化学],
 isnull(sum(case stdsubject when '数学' then Result end),0) [数学],
 isnull(sum(case stdsubject when '物理' then Result end),0) [物理],
 isnull(sum(case stdsubject when '语文' then Result end),0) [语文] 
 from #student 
 group by stdname 

 

posted @ 2016-07-27 13:59  谁的青春不迷茫  阅读(128)  评论(0)    收藏  举报