Commit bb923ace by michael lundquist

### Done with ch9 hands on stuff

parent 61d98539

13 KB | W: | H:

15.8 KB | W: | H:

• 2-up
• Swipe
• Onion skin
 ... @@ -35,8 +35,7 @@ Problem 5 ... @@ -35,8 +35,7 @@ Problem 5 Determine the profit of each book sold to Jake Lucas, using the actual price the customer paid (not the book's regular retail price). Sort the results by order date. If more than one book was ordered, sort the results by profit amount in descending order. Perform the search using the customer name, not the customer number Determine the profit of each book sold to Jake Lucas, using the actual price the customer paid (not the book's regular retail price). Sort the results by order date. If more than one book was ordered, sort the results by profit amount in descending order. Perform the search using the customer name, not the customer number */ */ --DOUBLE CHECK THIS SELECT ISBN, QUANTITY * (PAIDEACH - COST) AS PROFIT, ORDERDATE FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) JOIN BOOKS B USING (ISBN) WHERE C.FIRSTNAME = 'JAKE' AND C.LASTNAME = 'LUCAS' ORDER BY ORDERDATE, (PAIDEACH - COST) DESC; SELECT ISBN, QUANTITY * (PAIDEACH - COST) AS PROFIT FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) JOIN BOOKS B USING (ISBN) WHERE C.FIRSTNAME = 'JAKE' AND C.LASTNAME = 'LUCAS' ORDER BY ORDERDATE; /** /** Problem 6 Problem 6 ... @@ -44,7 +43,6 @@ Problem 6 ... @@ -44,7 +43,6 @@ Problem 6 Which books were written by an author with the last name Adams? Perform the search using the author name. Which books were written by an author with the last name Adams? Perform the search using the author name. */ */ --DOUBLE CHECK THIS SELECT ISBN, TITLE FROM BOOKS B JOIN BOOKAUTHOR BA USING (ISBN) JOIN AUTHOR A USING (AUTHORID) WHERE A.LNAME = 'ADAMS'; SELECT ISBN, TITLE FROM BOOKS B JOIN BOOKAUTHOR BA USING (ISBN) JOIN AUTHOR A USING (AUTHORID) WHERE A.LNAME = 'ADAMS'; /** /** ... @@ -69,16 +67,13 @@ Problem 9 ... @@ -69,16 +67,13 @@ Problem 9 Display a list of all books in the BOOKS table. If a book has been ordered by a customer, also list the corresponding order number and the state in which the customer resides. Display a list of all books in the BOOKS table. If a book has been ordered by a customer, also list the corresponding order number and the state in which the customer resides. */ */ /** SELECT TITLE, STATE, ORDER# FROM CUSTOMERS JOIN ORDERS USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) RIGHT OUTER JOIN BOOKS USING (ISBN) ORDER BY TITLE; SELECT B.TITLE, C.STATE, OI.ORDER# FROM BOOKS B, CUSTOMERS C, ORDERITEMS OI, ORDERS O WHERE C.CUSTOMER# = O.CUSTOMER# AND O.ORDER# = OI.ORDER# AND OI.ISBN = B.ISBN (+); */ SELECT B.TITLE, C.STATE, OI.ORDER# FROM BOOKS B, CUSTOMERS C, ORDERITEMS OI, ORDERS O WHERE C.CUSTOMER# = O.CUSTOMER# AND O.ORDER# = OI.ORDER# AND OI.ISBN = B.ISBN (+); SELECT TITLE, STATE, ORDER# FROM CUSTOMERS JOIN ORDERS USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) RIGHT OUTER JOIN BOOKS USING (ISBN); /** /** Problem 10 Problem 10 An EMPLOYEES table was added to the JustLee Books database to track employee information. Display a list of each employee's name, job title, and manager's name. Use column aliases to clearly identify employee and manager name values. Include all employees in the list and sort by manager name.*/ An EMPLOYEES table was added to the JustLee Books database to track employee information. Display a list of each employee's name, job title, and manager's name. Use column aliases to clearly identify employee and manager name values. Include all employees in the list and sort by manager name. \ No newline at end of file */ SELECT E.FNAME || ' ' || E.LNAME AS EMPLOYEE_NAME, E.JOB AS TITLE, M.FNAME || ' ' || M.LNAME AS MGR_NAME FROM EMPLOYEES E, EMPLOYEES M WHERE NVL(E.MGR, 7839) = M.EMPNO ORDER BY M.LNAME, M.FNAME; \ No newline at end of file
 ## problem 1 Create a list that displays the title of each book and the name and phone number of the contact at the publisher's office for reordering each book ```sql SELECT P.NAME, P.PHONE, B.TITLE FROM BOOKS B, PUBLISHER P WHERE P.PUBID = B.PUBID; ``` ![PROBLEM 1](./PICS/PROBLEM1.PNG) ## problem 2 Determine which orders haven't yet shipped and the name of the customer who placed the order. Sort the results by the date on which the order was placed.*/ ```sql SELECT C.FIRSTNAME, C.LASTNAME, O.ORDER# FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) WHERE SHIPDATE IS NULL ORDER BY ORDERDATE; ``` ![PROBLEM2](./PICS/PROBLEM2.PNG) ## problem 3 Produce a list of all customers who live in the state of Florida and have ordered books about computers ```sql SELECT C.FIRSTNAME, C.LASTNAME FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) JOIN BOOKS B USING (ISBN) WHERE C.STATE = 'FL' AND B.CATEGORY = 'COMPUTER'; ``` ![PROBLEM3](./PICS/PROBLEM3.PNG) ## problem 4 Determine which books customer Jake Lucas has purchased. Perform the search using the customer name, not the customer number. If he has purchased multiple copies of the same book, unduplicate the results. ```sql SELECT UNIQUE ISBN FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) JOIN ORDERITEMS USING (ORDER#) JOIN BOOKS USING (ISBN) WHERE C.FIRSTNAME = 'JAKE' AND C.LASTNAME = 'LUCAS'; ``` ![PROBLEM4](./PICS/PROBLEM4.PNG) ## Problem 5 Determine the profit of each book sold to Jake Lucas, using the actual price the customer paid (not the book's regular retail price). Sort the results by order date. If more than one book was ordered, sort the results by profit amount in descending order. Perform the search using the customer name, not the customer number ```sql SELECT ISBN, QUANTITY * (PAIDEACH - COST) AS PROFIT, ORDERDATE FROM CUSTOMERS C JOIN ORDERS O USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) JOIN BOOKS B USING (ISBN) WHERE C.FIRSTNAME = 'JAKE' AND C.LASTNAME = 'LUCAS' ORDER BY ORDERDATE, (PAIDEACH - COST) DESC; ``` ![PROBLEM5](./PICS/PROBLEM5.PNG) ## Problem 6 Which books were written by an author with the last name Adams? Perform the search using the author name. ```sql SELECT ISBN, TITLE FROM BOOKS B JOIN BOOKAUTHOR BA USING (ISBN) JOIN AUTHOR A USING (AUTHORID) WHERE A.LNAME = 'ADAMS'; ``` ![problem6](./PICS/PROBLEM6.PNG) ## Problem 7 What gift will a customer who orders the book "Shortest Poems" receive? Use the actual book retail value to determine the gift ```sql SELECT GIFT FROM PROMOTION WHERE (SELECT RETAIL FROM BOOKS WHERE TITLE = 'SHORTEST POEMS') BETWEEN MINRETAIL AND MAXRETAIL; ``` ![PROBLEM7](./PICS/PROBLEM7.PNG) ## Problem 8 Identify the authors of the books Becca Nelson ordered. Perform the search using the customer name. ```sql SELECT FNAME, LNAME FROM CUSTOMERS C JOIN ORDERS USING (CUSTOMER#) JOIN ORDERITEMS USING (ORDER#) JOIN BOOKS USING (ISBN) JOIN BOOKAUTHOR USING (ISBN) JOIN AUTHOR A USING (AUTHORID) WHERE C.LASTNAME = 'NELSON' AND C.FIRSTNAME = 'BECCA'; ``` ![PROBLEM8](./PICS/PROBLEM8.PNG) ## Problem 9 Display a list of all books in the BOOKS table. If a book has been ordered by a customer, also list the corresponding order number and the state in which the customer resides. ```sql SELECT TITLE, STATE, ORDER# FROM CUSTOMERS JOIN ORDERS USING (CUSTOMER#) JOIN ORDERITEMS OI USING (ORDER#) RIGHT OUTER JOIN BOOKS USING (ISBN); ``` ![PROBLEM9A](./PICS/PROBLEM9A.PNG) ![PROBLEM9B](./PICS/PROBLEM9B.PNG) ## Problem 10 An EMPLOYEES table was added to the JustLee Books database to track employee information. Display a list of each employee's name, job title, and manager's name. Use column aliases to clearly identify employee and manager name values. Include all employees in the list and sort by manager name. ```SQL SELECT E.FNAME || ' ' || E.LNAME AS EMPLOYEE_NAME, E.JOB AS TITLE, M.FNAME || ' ' || M.LNAME AS MGR_NAME FROM EMPLOYEES E, EMPLOYEES M WHERE NVL(E.MGR, 7839) = M.EMPNO ORDER BY M.LNAME, M.FNAME; ``` ![PROBLEM 10](./PICS/PROBLEM10.PNG) \ No newline at end of file