Write a SELECT statement that returns these columns from the Invoices table: The invoice_number column The invoice_date column The invoice_date column plus 30 days The payment_date column A column named days_to_pay that shows the number of days between the invoice date and the payment date The number of the invoice date’s month The four-digit year of the invoice date When you have this working, add a WHERE clause that retrieves just the invoices for the month of May based on the invoice date, not the number of the invoice month

Respuesta :

This query would work on an Oracle database:

SELECT

invoice_number,

invoice_date,

invoice_date+30,

payment_date,

payment_date-invoice_date AS days_to_pay,

to_date(invoice_date, 'MM'),

to_date(invoice_date, 'YYYY')

FROM Invoices

WHERE to_char(to_date(invoice_date, 'MM')) = '05'

In fact, the operation with dates are allowed there (i.e. date+1 means "the day after the date"), and date1-date2 return the days between the two dates.