11.07.2015 Views

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

534 CHAPTER 12 ■ DATA WAREHOUSINGon the QUANTITY_RENTED column. The cost-based optimizer is optimized to handle pivot aggregationsmore efficiently in <strong>Oracle</strong> <strong>Database</strong> <strong>11</strong>g.The pivot clause can be specified with multiple pivot columns. Additional options includethe capability to aggregate on multiple columns, use wildcards, and use aliases. You can pivoton multiple aggregations using the syntax pivot (expression) as Alias, (expression) asAlias2 for column. The pivot column must be a column of the table. If an expression needs tobe pivoted, you should create an alias. Now we’ll show an example of pivoting on multiplecolumns. This example will use the alias names for the pivoted columns to perform the sorting:1 select *2 from (select video_name, month, quantity_rented, rental_type3 from video_mstr_vw) pivot (sum(quantity_rented)4 for (rental_type, month) in (5 (10000, '01') as SR_jan,6 (10001, '01') as IR_jan,7 (10000, '02') as SR_feb,8 (10001, '02') as IR_feb9 )10 )<strong>11</strong>* order by SR_jan, IR_jan, SR_feb, IR_febSQL> /VIDEO_NAME SR_JAN IR_JAN SR_FEB IR_FEB---------------------- ---------- ---------- ---------- ----------The Pacifier 7500Mission Impossible III 10000Ray 15500Madagascar 47500Open Season 4500Walk the Line 5500Lord of War <strong>11</strong>500Superman Returns 20000Sin City 10500Hostage 14500Fantastic Four 65500....Note that the output results in four aliased columns (SR_JAN, IR_JAN, SR_FEB, and IR_FEB)from the in list. If the in list does not have an alias, the column heading will be same as thevalues specified in the in list. Notice that we are able to leverage the alias names in the order byclause. You can see from the next example that without aliases in the in list, the column headingshave the values of the in_clause as the column headings:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!