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 do a unioun of two pivot queries

NessMay 16 2019 — edited May 17 2019

hi all

m using pl sql devloper.

i want to do a union of two pivot queries.

below is my query:

select * from

(

       select t5.invoice_no,t5.invoice_line_no,t5.invoice_item_no,t5.ftype,t5.amount--,t.sort_order

       from air_inv_item_fare_compo t5

       where t5.invoice_no ='A002N2'

       and t5.invoice_line_no =1

       and t5.invoice_item_no =1

)

pivot

(      sum(amount)

       for ftype in ('BaseFare','UDF','JN','OB','OC','VMPD','BaggageCost'

         ,'MealCharge','SeatCharge','Commission','YR','OtherTaxes')

)

union

select * from

(

       select t6.invoice_no,t6.invoice_line_no,t6.invoice_item_no,t6.dtype,t6.amount--,t.sort_order

       from  air_inv_item_fees_disc t6

       where t6.invoice_no ='A002N2'

       and t6.invoice_line_no =1

       and t6.invoice_item_no =1

)

pivot

(      sum(amount)

       for dtype in ('BookingFee','PaymentFee','Discount','SupplierAmendmnetFee')

)

the issue is when i run the individual queries ,i get the output ,but when i try to do union of the two queries i get error query block has incorrect no of result columns

Pl help.

Comments
Post Details
Added on May 16 2019
11 comments
10,232 views