溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

oracle pivot 和 unpivot 函數(shù)的使用

發(fā)布時間:2020-06-27 22:46:37 來源:網(wǎng)絡(luò) 閱讀:3327 作者:love灬少 欄目:關(guān)系型數(shù)據(jù)庫

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

轉(zhuǎn)換多個列
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)
);

在轉(zhuǎn)換中使用多個聚合函數(shù)
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可以實現(xiàn)列轉(zhuǎn)行,所轉(zhuǎn)的列的字段類型必須一致
unpivot 的用法舉例:
select * from PIVOT_SALES_DATE
unpivot (amount for month in (JAN,FEB,MAR,APR));

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI