Professional Documents
Culture Documents
8. Display Vendor ID and Vendor Names for vendors that have no invoices.
--using a subquery
Query List #3
1. Display Vendor name, number of invoices for each vendor, and average invoice
total for each vendor that has average invoice amount greater than $500. Display in
ascending order of average invoice total values. (HAVING)
2. Display Vendor name, number of invoices for each vendor, and average invoice
total for each vendor for all invoices with Invoice Total amount greater than $500.
(WHERE)
3. Display invoice date, number of invoices, total of invoice totals for invoice
dates between May 1, 2006 and May 31, 2006. Only display information for those
dates for which there are more than one invoices and the sum of invoice totals is
greater than $100.
5. List Vendor names, Invoice numbers and Invoice totals for all invoices that are
larger than the largest invoice total for vendor 34. List output in ascending order
of vendor name.
6. List Invoice number, Invoice date and Invoice totals for vendors from
California. Sort output by Invoice date in ascending order.
7. Display Vendor state, city, number of invoices, and average invoice total for
vendors located in each city. Display only cities that have more than two vendors.
--Use of implicit INNER JOIN syntax and table alias (correlation name) to
--join the Vendors, Invoices and InvoiceLineItems tables
SELECT *
FROM VENDORS, INVOICES, InvoiceLineItems AS InvLine
WHERE VENDORS.VENDORID = INVOICES.VENDORID AND INVOICES.INVOICEID =
InvLine.InvoiceID
ORDER BY VendorName;
--Use of explicit INNER JOIN syntax and table alias (correlation name) to
--join the Vendors, Invoices and InvoiceLineItems tables
SELECT *
FROM VENDORS INNER JOIN INVOICES ON VENDORS.VENDORID = INVOICES.VENDORID
INNER JOIN InvoiceLineItems AS InvLine ON INVOICES.InvoiceID = InvLine.InvoiceID
ORDER BY VendorName;
--Use of the LIKE operator to find all vendors with VendorNames beginning with
letter I.
--Percent symbol (%) and underscore (_) are two wild characters we can use with the
LIKE operator.
SELECT *
FROM VENDORS
WHERE VENDORNAME LIKE 'I%'
GO
--Creating a VIEW
GO
--To display data from the VIEW created, use the view TESTINVOICES as the data
source in the FROM clause
--of a SELECT statement
SELECT *
FROM TESTINVOICES;