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://bzwzjz.com/article/poceed.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站设计制作报价 成都网站制作 成都网站设计 重庆企业网站建设 成都营销网站制作 成都定制网站建设 成都网站设计公司 成都网站制作 企业网站设计 外贸营销网站建设 自适应网站建设 成都网站设计 成都网站建设公司 成都网站设计 网站制作报价 成都网站制作 成都网站制作 手机网站设计 成都网站建设公司 阿坝网站设计 成都网站制作 网站建设改版