http://www.cnblogs.com/NewLand/archive/2007/09/03/880540.html



 Create   table   test   ( [name] char(10), km char(10)   , cj int )
 
Go
 
--初始化数据
 insert   into   test   values('张三','语文',80)
 
insert   into   test   values('张三','数学',86)
 
insert   into   test   values('张三','英语',75)
 
insert   into   test   values('李四','语文',78)
 
insert   into   test   values('李四','数学',85)
 
insert   into   test   values('李四','英语',78)
 
Go

select name,sum(case km when '语文' then cj  endas 语文,
 
sum(case km when '数学' then cj  endas 数学,
 
sum(case km when '英语' then cj  endas 英语
 
from test
 
group by name

相关文章: