【转】SQLServer 行列互换
2009-03-22 05:21
405 查看
http://www.cnblogs.com/NewLand/archive/2007/09/03/880540.html
--行列互换
Use tempdb
Go
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 end) as 语文,
sum(case km when '数学' then cj end) as 数学,
sum(case km when '英语' then cj end) as 英语
from test
group by name
--行列互换
Use tempdb
Go
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 end) as 语文,
sum(case km when '数学' then cj end) as 数学,
sum(case km when '英语' then cj end) as 英语
from test
group by name
相关文章推荐
- [SQLServer]数据库行列互换
- MS-SQLServer 2000 T-SQL 交叉报表(行列互换) 交叉查询 旋转查询
- sqlServer语句进行行列互换一
- MS-SQLServer 2000 T-SQL 交叉报表(行列互换) 交叉查询 旋转查询
- MS-SQLServer 2000 T-SQL 交叉报表(行列互换) 交叉查询 旋转查询
- [SQLServer]数据库行列互换
- Oracle 行列互换
- Oracle行列互换 横表和纵表
- SQL Server2005杂谈(1):将聚合记录集逆时针和顺时针旋转90度(行列互换)
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
- 行列互换的一个实例
- MS_SQL SERVER 行列互换 通用版
- SQLServer中行列转换Pivot UnPivot
- SQL延伸2-最简单的行列互换
- SQL 行列互换
- 将二维list的行列互换
- 数据表行列互换的一个思考
- sql行列互换问题
- mysql行列互换
- Oracle 11g 行列互换 pivot 和 unpivot 说明