Berikut adalah cara penggunaan Pivot pada Oracle
Contoh 1 :
select cust_id, state_code, times_purchased
from customers
order by cust_id;
Output :
Contoh 2 : Group
select state_code, times_purchased, count(1) cnt
from customers
group by state_code, times_purchased;
Output :
Contoh 3 : Pivot
select * from (
select times_purchased, state_code
from customers t
)
pivot
(
count(state_code)
for state_code in ('NY','CT','NJ','FL','MO')
)
order by times_purchased
/
Output :
Contoh 5 : Pivot
select * from (
select times_purchased as "Puchase Frequency", state_code
from customers t
)
pivot
(
count(state_code)
for state_code in ('NY' as "New York",'CT' "Connecticut",'NJ' "New Jersey",'FL' "Florida",'MO' as "Missouri")
)
order by 1
/
Output :