0% found this document useful (0 votes)
13 views3 pages

SQL Assignment

This document contains 9 SQL queries that retrieve and filter data from invoices and vendors tables in a database. The queries: 1) Order invoices by total amount descending 2) Filter and sort vendor contacts by last name then first name 3) Calculate percentages and sort invoices between $500-$1000 by due date

Uploaded by

saikiranypv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

SQL Assignment

This document contains 9 SQL queries that retrieve and filter data from invoices and vendors tables in a database. The queries: 1) Order invoices by total amount descending 2) Filter and sort vendor contacts by last name then first name 3) Calculate percentages and sort invoices between $500-$1000 by due date

Uploaded by

saikiranypv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

**********************SQL ASSIGNMENT*******************************

1. Retrieve the invoice_number, invoice_date, and invoice_total from the invoices


table, and arrange the results in descending order based on the invoice_total.

SELECT invoice_number, invoice_date, invoice_total


FROM invoices
ORDER BY invoice_total DESC;

2. Return three columns from vendors table, vendor_name, vendor_contact_first_name,

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;

3. Retrieve the invoice_due_date (renamed as "Due Date"), invoice_total (renamed as


"Invoice Total"), 10% of the invoice_total (as "10%"), and the invoice_total
increased by 10% (as "Plus 10%") from the invoices table. Filter the results to
include only invoices with a total amount between $500 and $1000. Sort the results
in descending order based on the invoice_due_date.

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;

4.selects invoice_number, invoice_date, the calculated balance_due (considering


payment and credit totals), and payment_date from the invoices table. The results
are filtered to include only those records where the payment_date is NULL,
indicating that no payment has been made for those invoices.

SELECT
invoice_number,
invoice_date,
invoice_total - payment_total - credit_total AS balance_due,
payment_date
FROM
invoices
WHERE
payment_date IS NULL;

5.Select the maximum sum of invoices for each vendor state:

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;

6.Select vendor names along with their latest invoice date:

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;

7.Select invoices for vendors in California using the IN clause:

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
);

You might also like