sql行转列

select * from tb

select 姓名,
 Max(case when [课程]='yuwen' then [分数]  end) as 语文,
 Max(case when [课程]='shuxue' then [分数]  end) as 数学,
 Max(case when [课程]='wuli' then [分数]  end) as 物理
from tb
group by 姓名


select * into temptb from
(select * from tb
pivot
(
    sum(分数)  for 课程 in ([yuwen],[shuxue],[wuli])
 )
as 
c) as d

select  from  temptb

 sp_help temptb
原文地址:https://www.cnblogs.com/anbylau2130/p/3447208.html