Professional Documents
Culture Documents
SQL Assignment
SQL Assignment
vendor_contact_last_name, Add order by sort the result by last name and then first
name, both asc
last name - a comma , a space , and the first name will be Doe, John
Last name - , Kumar First Name - Anton and Bill
Return only the contacts whose last name begins with letter A, B, C, or E.
Hint % , _.
SELECT
vendor_name,
vendor_contact_first_name,
vendor_contact_last_name
FROM
vendors
WHERE
vendor_contact_last_name LIKE 'A%'
OR vendor_contact_last_name LIKE 'B%'
OR vendor_contact_last_name LIKE 'C%'
OR vendor_contact_last_name LIKE 'E%'
ORDER BY
vendor_contact_last_name,
vendor_contact_first_name;
SELECT
invoice_due_date AS "Due Date",
invoice_total AS "Invoice Total",
ROUND(invoice_total * 0.1, 2) AS "10%",
ROUND(invoice_total * 1.1, 2) AS "Plus 10%"
FROM
invoices
WHERE
invoice_total BETWEEN 500 AND 1000
ORDER BY
invoice_due_date DESC;
SELECT
invoice_number,
invoice_date,
invoice_total - payment_total - credit_total AS balance_due,
payment_date
FROM
invoices
WHERE
payment_date IS NULL;
SELECT
vendor_state,
MAX(invoice_total) AS max_invoice_total
FROM
vendors
JOIN invoices ON vendors.vendor_id = invoices.vendor_id
GROUP BY
vendor_state;
SELECT
vendor_name,
MAX(invoice_date) AS latest_invoice_date
FROM
vendors
JOIN invoices ON vendors.vendor_id = invoices.vendor_id
GROUP BY
vendor_name;
SELECT * FROM
invoices
WHERE
vendor_id IN (
SELECT
vendor_id
FROM
vendors
WHERE
vendor_state = 'CA'
);
8.Select invoices, including details from the vendors, for invoices related to
vendors in California:
SELECT
i.*,
v.*
FROM
invoices i
JOIN vendors v ON i.vendor_id = v.vendor_id
WHERE
v.vendor_state = 'CA';
9. Select invoices with a total greater than the average invoice total:
SELECT
*
FROM
invoices
WHERE
invoice_total > (
SELECT
AVG(invoice_total)
FROM
invoices
);