横纵表的相互转换!
来源:百度知道 编辑:UC知道 时间:2024/06/15 17:07:25
--行列互转
/******************************************************************************************************************************************************
以学生成绩为例子,比较形象易懂
整理人:中国风(Roy)
日期:2008.06.06
******************************************************************************************************************************************************/
--1、行互列
--> --> (Roy)生成测试数据
if not object_id('Class') is null
drop table Class
Go
Create table Class([student] nvarchar(2),[subject] nvarchar(2),[grade] int)
Insert Class
select N'张三',N'语文',78 union all
select N'张三',N'数学',87 union all
select N'张三',N'英语',82 union all
select N'张三',N'物理',90 union all
select N'李四',N'语文',65 union all
select N'李四',N'数学',77 union all
select N'李四',N'英语',65 union all
se