FREE DOWNLOAD

Book Publishing Database Queries

SOLUTION FILE AVAILABLE AT: http://libraay.com/downloads/bookstore-publishing-database-queries/

Problem:

  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 Scribner, list the book code, book title, and price.
  3. List the book title, book code, and price of each book published by Scribner 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 3.
  5. List the book title for each book that has the type PSY and that is published by Berkley Publishing.
  6. Find the book title for each book written by author number 18. Use the IN operator in your query.
  7. Find the book title for each book written by author number 18. Use the EXISTS operator in your query.
  8. Find the book code and book title for each book located in branch number 2 and written by author 20.
  9. List the book codes for each pair of books that have the same price and list the 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.
  10. Find the book title, author last name, and units on hand for each book in branch number 4.
  11. Find the book title, author last name, and units on hand for each paperback book in branch number 4.
  12. Find the book code and book title for each book whose price is more than $10 or that was published in Boston.
  13. Find the book code and book title for each book whose price is more than $10 and that was published in Boston.
  14. Find the book code and book title for each book whose price is more than $10 but that was not published in Boston.
  15. 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 MYS.
  16. 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 MYS.

Solution:

SELECT BOOK_CODE, TITLE, B.PUBLISHER_CODE, PUBLISHER_NAME
FROM BOOK B
JOIN PUBLISHER P on P.PUBLISHER_CODE = B.PUBLISHER_CODE
ORDER BY PUBLISHER_NAME;

SELECT BOOK_CODE, TITLE, PRICE
FROM BOOK B
JOIN PUBLISHER P on P.PUBLISHER_CODE = B.PUBLISHER_CODE
AND P.PUBLISHER_NAME LIKE ‘Scribner’;

SELECT TITLE, B.BOOK_CODE, PRICE
FROM BOOK B
JOIN PUBLISHER P ON P.PUBLISHER_CODE = B.PUBLISHER_CODE
WHERE B.PUBLISHER_CODE = ‘SC’ AND PRICE >= 14;

SELECT I.BOOK_CODE, TITLE, ON_HAND
FROM BOOK B
JOIN INVENTORY I ON I.BOOK_CODE = B.BOOK_CODE
WHERE BRANCH_NUM = 3;

SELECT TITLE
FROM BOOK B
JOIN PUBLISHER P
ON B.PUBLISHER_CODE = P.PUBLISHER_CODE
WHERE P.PUBLISHER_CODE LIKE ‘BP’
AND B.TYPE LIKE ‘PSY’;

SELECT TITLE
FROM BOOK B
WHERE B.BOOK_CODE IN (SELECT W.BOOK_CODE FROM WROTE W
WHERE W.AUTHOR_NUM = 18);

SELECT TITLE
FROM BOOK B
WHERE EXISTS (SELECT *
FROM WROTE W
WHERE B.BOOK_CODE = W.BOOK_CODE
AND W.AUTHOR_NUM = 18);

SELECT I.BOOK_CODE, TITLE
FROM BOOK B
JOIN INVENTORY I ON I.BOOK_CODE = B.BOOK_CODE
WHERE BRANCH_NUM = 3;

SELECT B1.BOOK_CODE, B2.BOOK_CODE
FROM BOOK B1
JOIN BOOK B2 ON B1.PRICE = B2.PRICE
GROUP BY B1.BOOK_CODE, B2.BOOK_CODE
HAVING B1.BOOK_CODE < B2.BOOK_CODE
ORDER BY B1.BOOK_CODE, B2.BOOK_CODE;

SELECT B.TITLE, A.AUTHOR_LAST, I.ON_HAND
FROM Book B, AUTHOR A , INVENTORY I ,wrote W
WHERE B.BOOK_CODE =I.BOOK_CODE
AND W.AUTHOR_NUM=A.AUTHOR_NUM
AND W.BOOK_CODE= B.BOOK_CODE
AND I.BRANCH_NUM=4;

SELECT B.TITLE, A.AUTHOR_LAST, I.ON_HAND
FROM Book B, AUTHOR A , INVENTORY I ,wrote W
WHERE B.BOOK_CODE =I.BOOK_CODE
AND W.AUTHOR_NUM=A.AUTHOR_NUM
AND W.BOOK_CODE= B.BOOK_CODE
AND I.BRANCH_NUM=4
AND B.PAPERBACK=’Y’;

SELECT BOOK_CODE, TITLE
FROM BOOK B
JOIN PUBLISHER P ON P.PUBLISHER_CODE = B.PUBLISHER_CODE
WHERE B.PRICE > 10
OR P.CITY = ‘BOSTON’;

SELECT BOOK_CODE, TITLE
FROM BOOK B
JOIN PUBLISHER P ON P.PUBLISHER_CODE = B.PUBLISHER_CODE
WHERE B.PRICE > 10
AND P.CITY = ‘BOSTON’;

SELECT BOOK_CODE, TITLE
FROM BOOK B
JOIN PUBLISHER P ON B.PUBLISHER_CODE = P.PUBLISHER_CODE
WHERE PRICE > 10 AND P.CITY != ‘BOSTON’

SELECT BOOK_CODE, TITLE, PUBLISHER_NAME
FROM BOOK B
JOIN PUBLISHER P ON B.PUBLISHER_CODE = P.PUBLISHER_CODE
WHERE PRICE > (SELECT MAX(PRICE)
FROM BOOK
WHERE TYPE = ‘MYS’);

SELECT BOOK_CODE, TITLE, PUBLISHER_NAME
FROM BOOK B
JOIN PUBLISHER P ON B.PUBLISHER_CODE = P.PUBLISHER_CODE
WHERE PRICE > (SELECT MIN(PRICE)
FROM BOOK
WHERE TYPE = ‘MYS’);

SOLUTION FILE AVAILABLE AT: http://libraay.com/downloads/bookstore-publishing-database-queries/

Leave a Reply

Your email address will not be published. Required fields are marked *



Solutions Authored by 15+ Years Experienced Industry Expert