Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q1: Q2: Q3: Q4: The following questions will all use the schema for a library database as follows. Books (isbn, title, author, genre, publisher) Members
Q1:
Q2:
Q3:
Q4:
The following questions will all use the schema for a library database as follows. Books (isbn, title, author, genre, publisher) Members (id, name) Lending (isbn, id, checkout, returned) // checkout and returned are both DATETIME A tuple in Books represents a single book in the library system (We're assuming the library doesn't have multiple copies of a book, and each book has a single author and publisher). There may be multiple books with the same title, and different isbn. The Members table holds identifying information for people checking out books from the library. There may be multiple people with the same name, and different member ids. Lastly the Lending table shows a history of books loaned to various members. The checkout and returned attributes are the time stamps the book was checked out to a user and subsequently returned by that user. Any Lending tuple with a NULL "returned" attribute means that book is still currently checked out. People may return a book and then check out the same book out again, each unique checkout becomes a new tuple with the new checkout time. Books.isbn is the primary key for Books. Members.id is the primary key for Members. Lending.isbn is a foreign key to Books.isbn Lending.id is a foreign key to Members.id. Lending.isbn, Lending.id, and Lending.checkout together constitute the primary key for Lending. isbn and id are INT type. checkout and returned are DATETIME type. All other attributes are VARCHAR(1000) Write the CREATE TABLE(...) statement for the Lending table in the schema described above. Use DATETIME for the type of the checkout and returned attributes, and INT for isbn and id. Remember to specify the relevant primary key and foreign key constraints. (You don't have to write .import or 'PRAGMA FOREIGN KEYS') Write a query to find the books currently checked out and the name of the person checking out each one. Return the member name and book title, both sorted alphabetically. (Hint: the 'IS NULL' boolean test is useful here) Write a query to find the number of book checkouts that have occurred in each genre of book in the library. (Multiple checkouts of the same book are still multiple checkouts in that genre.) If there is a genre that has some books in the library but none have ever been checked out, that genre's count should be 0 in the output. Return the genre and number of checkouts, sorted by number of checkouts in decreasing order. Find the names and ids of all people who checked out the book titled 'Leaves of Grass' and also checked out the book titled 'Harmonium' at some point (it is not required that the person had both books at once.) Return the id and name for each person who has checked out both books. Do not return duplicate tuplesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started