oraclepivot和unpivot函数的使用
pivot的格式
select from
( inner_query)
pivot(aggreate_function for pivot_column in ( list of values))
order by ...;
用法举例:
select
from (
select month,prd_type_id,amount
from all_sales
)
pivot (sum(amount) for month in (1 as JAN,2 as FEB,3 as MAR,4 as APR)
)
order by prd_type_id
成都创新互联自2013年创立以来,先为永德等服务建站,永德等地企业,进行企业商务咨询服务。为永德企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
转换多个列
select * from
(select month,prd_type_id,amount
from all_sales
)
pivot(sum(amount) for (month,prd_type_id) in (
(1,2) as JAN_P2,(2,3) as FEB_P3)
);
在转换中使用多个聚合函数
select * from (select cust_no,mag_man_cert_type,t.mag_man_cert_no,mag_man_type from L_CIF_ENT_CUST_MAG_MAN_INFO t
pivot (max(mag_man_cert_NO) as no ,max(mag_man_cert_type) as type for mag_man_type In ('01' as GLR01,'02' as GLR02,'03' as GLR03));
unpivot可以实现列转行,所转的列的字段类型必须一致
unpivot 的用法举例:
select * from PIVOT_SALES_DATE
unpivot (amount for month in (JAN,FEB,MAR,APR));
网页题目:oraclepivot和unpivot函数的使用
当前网址:http://ybzwz.com/article/poceed.html