这些天看了些sql2005的知识,突然想到sql2005下的行列转化还没有结束。
看了下原来的要求,简单的写出sql2005下的行列转化结果。
代码如下:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
declare @table table
(
ID int ,
course varchar(10),
Point int
)
insert into @table
select 1 ,'语文',87
union all
select 1 ,'数学',98
union all
select 2,'语文',54
union all
select 3,'语文',97
union all
select 3,'数学',92
union all
select 4,'数学',86
union all
select 5 ,'数学',65
union all
select 6,'语文',76
select ID ,
isnull([数学],0) [数学] ,
isnull([语文],0) [语文]
from @table
pivot
(
sum(point)
for course
in ([数学],[语文])
) as pvt
原文:http://www.cnblogs.com/redfox241/archive/2009/05/21/1474685.html
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16436858/viewspace-604074/
,如需转载,请注明出处,否则将追究法律责任。