Write a SELECT statement that returns the following columns from the invoices ta
ID: 3917694 • Letter: W
Question
Write a SELECT statement that returns the following columns from the invoices table: invoice_number and invoice_total. Additionally, add the following calculations:
a. Add payment_total to credit_total and alias this as payment_credit_total
invoice_total minus payment_total and credit_total and alias this as balance_due
b. Write the same SELECT statement and sort the results by the balance due in descending order.
c. Write the same SELECT statement and add limits the results to the results with the 5 largest balances due.
d. Write the same SELECT statement and add the payment_date column to the SELECT clause.
e. Use a WHERE clause that limits the results to only those rows with a NULL value in the payment_date column
Explanation / Answer
Following is the answer:
a)
select invoice_number, invoice_total, (payment_total + credit_total) as "payment_credit_total", ((invoice_total -payment_total),credit_total) as "balance_due" from invoices
b)
select invoice_number, invoice_total, (payment_total + credit_total) as "payment_credit_total", ((invoice_total -payment_total),credit_total) as "balance_due" from invoices order by balance_due desc
c)
select invoice_number, invoice_total, (payment_total + credit_total) as "payment_credit_total", ((invoice_total -payment_total),credit_total) as "balance_due" from invoices order by balance_due desc limit 5
d)
select invoice_number, invoice_total, (payment_total + credit_total) as "payment_credit_total", ((invoice_total -payment_total),credit_total) as "balance_due", "payment_date" as payment_date from invoices order by balance_due desc limit 5
e)
select invoice_number, invoice_total, (payment_total + credit_total) as "payment_credit_total", ((invoice_total -payment_total),credit_total) as "balance_due", "payment_date" as payment_date from invoices where payment_date IS NOT NULL order by balance_due desc limit 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.