Question
Questions:(11,13,14)
Henry Books Use MySQL and the Henry Books database (Figures 1-4 through 1-7 in Chapter 1) to complete the following exercises. Use the notes at the end of Chapter 3 to print your output if directed to do so by your instructor. 1. For each book, list the book code, book title, publisher code, and publisher name. Order the results by publisher name. 2. For each book published by Plume, list the book code, book title, and price. 3. List the book title, book code, and price of each book published by Plume that has a book price of at least $14. 4. List the book code, book title, and units on hand for each book in branch number 4. 5. List the book title for each book that has the type PSY and that is published by Jove 6. Find the book title for each book written by author number 18. Use the IN operator in your 7. Repeat Exercise 6, but this time use the EXISTS operator in your formulation. Find the book code and book title for each book located in branch number 2 and written by author 20. List the book codes for each pair of books that have the same price. (For example, one such pair would be book 0200 and book 7559, because the price of both books is $8.00.) The first book code listed should be the major sort key, and the second book code should be the minor sort key. Find the book title, author last name, and units on hand for each book in branch number 4. Repeat Exercise 10, but this time list only paperback books. Find the book code and book title for each book whose price is more than $10 or that was published in Boston. Find the book code and book title for each book whose price is more than $10 and that was published in Boston. Find the book code and book title for each book whose price is more than $10 but that was not published in Boston. Find the book code and book title for each book whose price is greater than the book price of every book that has the type HOR. Find the book code and book title for each book whose price is greater than the price of at least one book that has the type HOR. List the book code, book title, and units on hand for each book in branch number 2. Be sure each book is included, regardless of whether there are any copies of the book currently on hand in branch 2. Order the output by book code. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.
Explanation / Answer
Answer is as follows:
SQL queries for 11,13 and 14 are as follows :
13)
SELECT Book_code, Title FROM Book JOIN Publisher ON Book.Publisher_Code = Publihser.Publisher_Code WHERE Publisher.City = 'Boston';
14)
SELECT Book_code, Title FROM Book JOIN Publisher ON Book.Publisher_Code = Publihser.Publisher_Code WHERE Publisher.City != 'Boston' ;
11) SELECT B.TITLE, A.AUTHOR_LAST, I.ON_HAND FROM BOOK B INNER JOIN INVENTORY I ON I.BOOK_CODE = B.BOOK_CODE INNER JOIN BRANCH BR ON BR.BRANCH_NUM = I.BRANCH_NUM INNER JOIN WROTE W ON W.BOOK_CODE = B.BOOK_CODE INNER JOIN AUTHOR A ON A.AUTHOR_NUM = W.AUTHOR_NUM WHERE BR.BRANCH_NUM = '4' GROUP BY B.PAPERBACK ;
or you can also use
SELECT B.TITLE, A.AUTHOR_LAST, I.ON_HAND FROM BOOK B INNER JOIN INVENTORY I ON I.BOOK_CODE = B.BOOK_CODE INNER JOIN BRANCH BR ON BR.BRANCH_NUM = I.BRANCH_NUM INNER JOIN WROTE W ON W.BOOK_CODE = B.BOOK_CODE INNER JOIN AUTHOR A ON A.AUTHOR_NUM = W.AUTHOR_NUM WHERE BR.BRANCH_NUM = '4' WHERE B.PAPERBACK = 'YES';
if there is any query please ask in comments..