Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create a Nested Pivot

Orcl ApexAug 22 2017 — edited Aug 24 2017

Hi All,

Query used:

SELECT *

FROM (SELECT ooha.org_id,

           ottt.name,

           mp.organization\_code,

           oola.attribute10,

           oola.line\_id

      FROM apps.oe\_transaction\_types\_tl  ottt,

           apps.oe\_transaction\_types\_all otta,

           apps.oe\_order\_headers\_all     ooha,

           apps.oe\_order\_lines\_all       oola,

           apps.mtl\_parameters           mp

     WHERE ottt.transaction\_type\_id = otta.transaction\_type\_id

       AND ottt.transaction\_type\_id = ooha.order\_type\_id

       AND otta.transaction\_type\_id = ooha.order\_type\_id

       AND ooha.header\_id = oola.header\_id

       AND oola.ship\_from\_org\_id = mp.organization\_id)

pivot(COUNT(line_id)

FOR organization_code IN('A',

                        'B',

                        'C',

                        'D',

                        'E',

                        'F',

                        'G',

                        'H',

                        'I'))

ORDER BY org_id, NAME, attribute10;

Output:

pastedImage_3.png

Desired output:

pastedImage_4.png

This post has been answered by Stew Ashton on Aug 24 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2017
Added on Aug 22 2017
20 comments
1,704 views