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!

Need help with SQL Query with Inline View + Group by

670697Nov 16 2008 — edited Nov 16 2008
Hello Gurus,

I would really appreciate your time and effort regarding this query. I have the following data set.

Reference_No Check_Number Check_Date Description Invoice_Number Invoice_Type Paid_Amount Vendor_Number
1234567 11223 7/5/2008 paid for cleaning 44345563 I *20.00* 19
1234567 11223 7/5/2008 Adjustment for bad quality 44345563 A -10.00 19
7654321 11223 7/5/2008 Adjustment from last billing cycle 23543556 A 50.00 19
4653456 11223 7/5/2008 paid for cleaning 35654765 I 30.00 19

I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.

The query should return the following data set

Reference_No Check_Number Payment_Date Description Invoice_Number Invoice_Type Paid_Amount Vendor_Number
1234567 11223 7/5/2008 paid for cleaning 44345563 I *10.00* 19
7654321 11223 7/5/2008 Adjustment from last billing cycle 23543556 A 50.00 19
4653456 11223 7/5/2008 paid for cleaning 35654765 I 30.00 19

The following is my query. I am kind of lost.

select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id


Thanks,
Nick
This post has been answered by Rob van Wijk on Nov 16 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2008
Added on Nov 16 2008
5 comments
464 views