Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Relational Database Schema for a Library Database: o BOOK(BKID, BK_TITLE, BK_LIS

ID: 3817224 • Letter: R

Question

Relational Database Schema for a Library Database:

o   BOOK(BKID, BK_TITLE, BK_LIST_PRICE, PBID)

o   PUBLISHER(PBID, PB_NAME, PB_STREET, PB_ZIPCODE, PB_PHONE)

o   AUTHOR(AUID, AU_NAME, AU_DOB)

o   LIBRARY_BRANCH(LBID, LB_NAME, LB_STREET, LB_ZIPCODE)

o   BORROWER(CRID, CR_NAME, CR_DOB, CR_STREET, CR_ ZIPCODE)

o   ZIPCODE(ZIPCODE, CITY, STATE)

o   BOOK_COPIES(BKID, LBID, NO_OF_COPIES)

o   BOOK_AUTHORS(BKID, AUID)

For each of the following, write the SQL query:

1.      List all the attributes for each Author born after January 18, 1976.

2.      List the Name and Date-of-Birth for each Author.

3.      List the Name and Date-of-Birth for each Author born after January 18, 1976.

4.      List the Title, List Price and Publisher’s Name for each Book.

5.      List the Title, List Price and Publisher’s Name for each Book whose List Price is more than $200.00.

6.      List the Title, List Price, Author’s Name and Publisher’s Name for each Book whose List Price is more than $200.00.

7.      List the ID, Name, City, State & Zipcode of each Publisher who has published at least one Book whose List Price was more than $200.00.

8.      List the number of books, and the minimum, average & maximum List Price for all books.

9.      List the Name, and average and maximum book List Price of each Publisher.

10. List number of Publishers who have published at least one Book whose List Price is more than $200.00.

11. List the ID & Name of each Publisher who has never published a Book whose List Price was more than $200.00.

12. List the ID & Name of each Publisher who only publishes Books whose List Price is more than $200.00.

In your Oracle APEX workspace:
1. Create BOOK, PUBLISHER, AUTHOR, ZIPCODE, and BOOK_AUTHORS tables based on attributes listed above. You can assume any appropriate and meaningful data type, domain and constraint for each attribute. (30 points)
2. In all created tables insert 4 different rows with random variables. (20 points)
3. Use AlTER TABLE command to rename PB_PHONE column in PUBLISHER table. The new name should be PB_PHONE_NUMBER. (10 points)
Develop queries for problem 5, 8,11 and 12 and run them one by one. For number 11 and 12 you can use IN, NOT IN and sub queries. Show the results and queries with screenshots. Screenshots should include your username in workspace. (40 points)

Explanation / Answer

NOTE : PLEASE NEVER POST THESE MANY QUESTIONS AT ONCE. WE ARE NOT ENTITLED TO ANSWER ALL.


1.  
SELECT * FROM AUTHOR WHERE AU_DOB > '1976-01-18';

2.
SELECT AU_NAME, AU_DOB FROM AUTHOR;

3.
SELECT AU_NAME, AU_DOB FROM AUTHOR WHERE AU_DOB > '1976-01-18';

4.
SELECT BK_TITLE, BK_LIST_PRICE, PBID FROM BOOK;

5.
SELECT BK_TITLE, BK_LIST_PRICE, PBID FROM BOOK WHERE BK_LIST_PRICE > 200.0;


6.
SELECT BK_TITLE, BK_LIST_PRICE, AU.AU_NAME, PB.PB_NAME
FROM BOOK AS BK JOIN PUBLISHER AS PB JOIN BOOK_AUTHOR AS BA JOIN AUTHOR AS AU
ON BK.PBID = PB.PBID AND BK.BKID = BA.BKID AND BA.AUID = AU.AUID
WHERE BK_LIST_PRICE > 200.0;


7.
SELECT PBID, PB_NAME, PB_STREET, ZC.CITY, ZC.STATE, ZC.ZIPCODE
FROM PUBLISHER AS PB JOIN ZIPCODE AS ZC
WHERE PB.PBID IN (SELECT DISTINCT PBID FROM BOOK WHERE BK_LIST_PRICE > 200.0);

8.
SELECT
COUNT(*) AS NUM_OF_BOOKS, MAX(BK_LIST_PRICE) AS MAX_PRICE,
MIN(BK_LIST_PRICE) AS MIN_PRICE, AVG(BK_LIST_PRICE) AS AVG_PRICE
FROM BOOK;

9.
SELECT PB_NAME, MAX_PRICE, AVG_PRICE
FROM PUBLISHER AS PB,
(SELECT PB_ID, MAX(BK_LIST_PRICE) AS MAX_PRICE, AVG(BK_LIST_PRICE) AS AVG_PRICE
FROM BOOK WHERE BK_LIST_PRICE > 200
GROUP BY PB_ID) AS TEMP
WHERE TEMP.PBID = PB.PB_ID;


10.
SELECT COUNT(DISTINCT PBID) FROM BOOK WHERE BK_LIST_PRICE > 200.0;


11.
SELECT PBID, PB_NAME
FROM PUBLISHER
WHERE PB.PBID NOT IN (SELECT DISTINCT PBID FROM BOOK WHERE BK_LIST_PRICE > 200.0);


12.
SELECT PBID, PB_NAME
FROM PUBLISHER
WHERE PB.PBID NOT IN (SELECT DISTINCT PBID FROM BOOK WHERE BK_LIST_PRICE < 200.0);