pivot用法
来源:互联网 发布:mac java开发必备软件 编辑:程序博客网 时间:2024/05/23 07:25
declare @tb table
(id int primary key identity(1,1),
name nvarchar(50),
课目 nvarchar(2),
分数 decimal(10,2)
)
insert into @tb
select '张三','语文',80
union all
select '张三','英语',95
union all
select '李四','语文',85
union all
select '李四','英语',93
union all
select '李四','数学',80
union all
select '张三','数学',90
---pivot 用法
select * from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
---pivot 加汇总行
select *,分数=语文+数学+英语 from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
----unpivot 用法
;with china as
(
select * from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
)
select * from china a
unpivot (分数 for 课目 in (语文,数学,英语))b
(id int primary key identity(1,1),
name nvarchar(50),
课目 nvarchar(2),
分数 decimal(10,2)
)
insert into @tb
select '张三','语文',80
union all
select '张三','英语',95
union all
select '李四','语文',85
union all
select '李四','英语',93
union all
select '李四','数学',80
union all
select '张三','数学',90
---pivot 用法
select * from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
---pivot 加汇总行
select *,分数=语文+数学+英语 from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
----unpivot 用法
;with china as
(
select * from (select name,课目,分数 from @tb) a pivot
(sum(分数) for 课目 in (语文,数学,英语)) b
)
select * from china a
unpivot (分数 for 课目 in (语文,数学,英语))b
- pivot 用法
- pivot用法
- pivot 用法
- pivot用法
- PIVOT用法详解
- PIVOT 用法详解
- 【转帖】PIVOT 用法浅尝
- PIVOT语句用法详解
- sql 2005 pivot 用法
- sql 2005 pivot 用法
- sql 2005 pivot 用法
- pivot的用法
- Pivot和UnPivot 用法
- SQL中PIVOT的用法
- PIVOT
- pivot
- PIVOT
- pivot
- StarUML中时序图添加小人
- CodeIgniter 核心代码阅读-安全文件Security.php
- spring beans.xml
- 时钟概念
- GtkAboutDialog中的一个陷阱
- pivot用法
- 完美terminator
- 善用win7中的资源监视器
- Oracle数据库的卸载
- android中的savedinstance
- Ubuntu中查看硬盘分区UUID的方法
- Ubuntu(Linux)使用Eclipse搭建C/C++编译环境
- C++ 智能指针详解
- em = px / 字体默认值 (font-size默认16px)