如何在Oracle 10g中进行数据透视 [英] How to do Pivoting in Oracle 10g
本文介绍了如何在Oracle 10g中进行数据透视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下内容
样本输入
SalesBoyName Product Amount
------------ ------- ------
Boy1 P1 100
Boy1 P1 40
Boy1 P2 100
Boy2 P1 100
Boy2 P3 12
所需的输出
SalesBoyName P1 P2 P3
------------ ---- ---- ----
Boy1 140 100 null
Boy2 100 null 12
下面的SQL SERVER 2005查询将完成工作
The below SQL SERVER 2005 query will do the work
SELECT SalesBoyName, [P1] AS P1, [P2] AS P2,[P3] AS P3
FROM
(SELECT * FROM tblSales ) s
PIVOT
(
SUM (Amount)
FOR Product IN
( [P1], [P2], [P3])
) AS pvt
我想在Oracle 10g中执行相同的操作.
I want to perform the same thing in Oracle 10g.
该怎么做?
这可能是微不足道的,但是由于我是Oracle的新手,所以我正在寻求帮助.
This may be trivial, but since i am very new to Oracle, so I am seeking for help.
谢谢
推荐答案
您可以在10G中做到这一点:
You can do it like this in 10G:
select salesboyname,
sum (case when product='P1' then amount end) as p1,
sum (case when product='P2' then amount end) as p2,
sum (case when product='P3' then amount end) as p3
from tblsales
group by salesboyname;
在11G中,有一个类似于SQL Server的PIVOT关键字.
In 11G there is a PIVOT keyword similar to SQL Server's.
这篇关于如何在Oracle 10g中进行数据透视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文