Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an INSERT statement that adds this row to the invoices table: invoice_i

ID: 3546897 • Letter: 1

Question

1.  Write an INSERT statement that adds this row to the invoices table:


invoice_id --> The next id in sequence ( find out what it should be ) which is 115

vendor_id --> 32

invoice_number --> AX-014-027

invoice_date --> 8/1/2008

invoice_total --> $434.58

payment_total --> $0.00

credit_total --> $0.00

terms_id --> 2

invoice_due_date --> 8/31/2008

payment_date --> null


My program below on problem one is getting an error (SQL command not properly ended - Error at Line 3 Colum: 1


select *

from invoice_copy10

insert into invoice_copy10

(invoice_id, vendor_id, invoice_number, invoice_date, invoice_total, payment_total, credit_total, terms_id, invoice_due_date, payment_date)

values (115, 32, AX-014-027, '01-AUG-08', 434.58, 0, 0, 2, '31-AUG-08', NULL);



2. Write a SELECT statement that returns a single value that represents the sum of the


largest unpaid invoices for each vendor (just one for each vendor).  Use an inline view that


returns MAX(invoice_total) grouped by vendor_id, filtering for invoices with a balance due.



3..  Write a SELECT statement that returns one row for each general ledger account number


that contains three colums


The account_description colum from General_ledger_Accounts table


The count of entries in the Invoice_Line_Items table that have the same account_number


The sum of the line item amounts in the Invoice_Line_Items table that have the same


account-number.


**Filter the result set to include only those rows with a counter greater than 1; group the result set by account description; and sort the result set in descending sequence by the sum of the line item amounts.


4,  Write a SELECT statement that answers this question:  Which invoices have a


payment_total that's greater than the average payment_total for all paid invoices?  Return


the invoice_number and invoice_total for each invoice


**I am using ORACLE SQL developer.

Explanation / Answer

1. put invoice_number in commas

insert into invoices

(invoice_id, vendor_id, invoice_number, invoice_date, invoice_total, payment_total, credit_total, terms_id, invoice_due_date, payment_date)

values (115, 32, 'AX-014-027', '01-AUG-08', 434.58, 0, 0, 2, '31-AUG-08', NULL);


4. SELECT Invoice_number, Invoice_total

FROM Invoices
WHERE PaymentTotal >
(SELECT Avg(PaymentTotal)

FROM Invoices)