标签:val 格式 rac 举例 多个 聚合 order mon oracl
pivot的格式转换多个列
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));
标签:val 格式 rac 举例 多个 聚合 order mon oracl
原文地址:http://blog.51cto.com/11225554/2150181