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

 

posted @ 2013-11-28 10:30  尼姑哪里跑  阅读(199)  评论(0编辑  收藏  举报