




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Exercises KimTay Pet Supplies
Answer: SELECT INVOICES.INVOICE_NUM, INVOICES.INVOICE_DATE, ITEM.ITEM_ID, ITEM.DESCRIPTION, ITEM.CATEGORY FROM INVOICES, INVOICE_LINE, ITEM WHERE INVOICES.INVOICE_NUM = INVOICE_LINE.INVOICE_NUM AND INVOICE_LINE.ITEM_ID = ITEM.ITEM_ID ORDER BY INVOICE_NUM;
AND ITEM.DESCRIPTION = 'Wild Bird Food (25 lb)'; 12.List the item ID, description, and category for each pair of items that are in the same category. (For example, one such pair would be item FS42 and item PF19, because the category for both items is FSH.) Answer: SELECT CATEGORY, ITEM_ID, DESCRIPTION FROM ITEM WHERE EXISTS (SELECT COUNT() FROM ITEM I WHERE I.CATEGORY = ITEM.CATEGORY GROUP BY CATEGORY HAVING COUNT() = 2) ORDER BY CATEGORY; 13.List the invoice number and invoice date for each invoice created for the customer James Gonzalez. Answer: SELECT INVOICE_NUM, INVOICE_DATE FROM INVOICES WHERE CUST_ID IN (SELECT CUST_ID FROM CUSTOMER WHERE FIRST_NAME = 'James' AND LAST_NAME = 'Gonzalez'); 14.List the invoice number and invoice date for each invoice that contains an invoice line for a Wild Bird Food (25 lb). Answer: SELECT INVOICES.INVOICE_NUM, INVOICES.INVOICE_DATE FROM INVOICES, INVOICE_LINE, ITEM
AND CUSTOMER.LAST_NAME = 'Gonzalez'; 17.List the invoice number and invoice date for each invoice that was created for James Gonzalez but that does not contain an invoice line for Wild Bird Food (25lb). Answer: SELECT DISTINCT INVOICES.INVOICE_NUM, INVOICES.INVOICE_DATE FROM INVOICES, INVOICE_LINE, ITEM, CUSTOMER WHERE INVOICES.INVOICE_NUM = INVOICE_LINE.INVOICE_NUM AND INVOICE_LINE.ITEM_ID = ITEM.ITEM_ID AND INVOICES.CUST_ID = CUSTOMER.CUST_ID AND ITEM.DESCRIPTION <> 'Wild Bird Food (25 lb)' AND CUSTOMER.FIRST_NAME = 'James' AND CUSTOMER.LAST_NAME = 'Gonzalez'; 18.List the item ID, description, unit price, and category for each item that has a unit price greater than the unit price of every item in category CAT. Use either the ALL or ANY operator in your query. ( Hint : Make sure you select the correct operator.) Answer: SELECT ITEM.ITEM_ID, ITEM.DESCRIPTION, ITEM.CATEGORY FROM ITEM WHERE ITEM.PRICE > ALL (SELECT PRICE FROM ITEM WHERE CATEGORY = 'CAT'); 19.For each item, list the item ID, description, units on hand, invoice number, and quantity ordered. All items should be included in the results. For those items that are currently not on an invoice, the invoice number and quantity
ordered should be left blank. Order the results by item ID. Answer: SELECT ITEM.ITEM_ID, ITEM.DESCRIPTION, ITEM.ON_HAND, INVOICE_LINE.INVOICE_NUM, INVOICE_LINE.QUANTITY FROM ITEM LEFT JOIN INVOICE_LINE ON (INVOICE_LINE.ITEM_ID = ITEM.ITEM_ID