oracle pivot 和 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 转换多个列 在转换中使用多个聚合函数 unpivot可以实现列转行,所转的列的字段类型必须一致unpivot 的用法举例:select * from PIVOT_SALES_DATE unpivot (amount for month in (JAN,FEB,MAR,APR)); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |