(a) How many copies of the book titled "The Lost Tribe" are owned by the library branch whose name is "Sharpstown"? (b) How many copies of the book titled "The Lost Tribe" are owned by each library branch? (c) Retrieve the names of all borrowers who do not have any books checked out. (d) For each book that is loaned out from the Sharpstown branch and whose DueDate is prior to "September 1, 2018", retrieve the book title, the borrower’s name, and the borrower’s address. (e) For each book authored (or coauthored) by Stephen King, retrieve the title and the number of copies owned by the library branch whose name is "Central". (f) Retrieve all book titles that are available in "Sharpstown" branch but not in "Morristown" branch. (g) Retrieve book titles that are available in all library branches in the database.

Respuesta :

Answer:

a) SELECT No_of_copies

FROM ((book JOIN book_copies) JOIN library_branch)

WHERE title = 'The Lost Tribe' AND branchname = 'Sharpstown';

b) SELECT branchname, No_of_copies

FROM ((book JOIN book_copies) JOIN library_branch)

WHERE title = 'The Lost Tribe'

GROUP BY branchname;

c) SELECT Name

FROM borrowers B

WHERE cardno NOT IN ( SELECT cardno FROM book_loan)

d) SELECT title, name, B.address

FROM (((book JOIN book_loan) JOIN library_branch) JOIN borrowers B)

WHERE duedate = '09/01/2018' AND branchname = 'Sharpstown';

e) SELECT title, No_of_copies

FROM (((book JOIN book_authors) JOIN book_copies) JOIN library_branch)

WHERE authorname = 'Stephen King' AND branchname = 'Central';

g) SELECT DISTINCT title

FROM ((book JOIN book_copies) JOIN library_branch)

Explanation:

The SQL statements query's a book store database of seven relations using joins and subqueries to return results.

RELAXING NOICE
Relax