SQLRun the SQL script given to you to create a Library database. Note that each row in the Book table denotes a book copy. Thus, if the library carries three copies of the title "DBMS", there will be three rows in the Book table , one for each copy Write the SQL statements to do the following against the database (Note: You must express your query in a single SQL statement for each of the following However, that statement could have sub-queries..).:
List the titles of all books written by "Churchill," along with their Year of Publication. Retrieve the titles of all books borrowed by members whose first name is "John" or "Susan". List the names and IDs of all members who have borrowed the "Iliad" and the "Odyssey" -both books. List the names and IDs of all the members who have borrowed all titles written by "Collins". Assume that a member may have borrowed multiple copies of the same title. Find the phone numbers of all members who have borrowed a book written by an author whose last name is "Tanenbaum." Find those members who have borrowed more than three books and list their names, IDs, and the number of books they borrowed. Sort the results in descending order based on the number of books borrowed. List all members who have not borrowed any book. List in alphabetical order the first names of all the members who are residents of Pittsburgh (Phone numbers starting with "412") and who have not Borrowed The Book Titled "Pitt Roads." TO HELP YOURSELF DO YOUR BEST ON This Assessment, Consult this general list of grading guidelines.
Go to Top of Question.
Script of the topic comes with the script: SQL for EXERCISE2.SQL:
DROP TABLE Author; DROP TABLE Book; DROP TABLE HOLD; DROP TABLE Dependent; DROP TABLE Title; DROP TABLE Member; DROP TABLE Section; DROP TABLE Librarian; CREATE TABLE Title (CallNumber VARCHAR (40) NOT NULL, Name VARCHAR (200), ISBN VARCHAR (40), Year DateTime, Publisher Varchar (80), PRIMARY Key (CallNumber), Unique (ISBN)); Create Table Author (40) Not Null, Fname Varchar (40) Not Null, Mi Varchar ( 10), Lname VARCHAR (40) NOT NULL, PRIMARY KEY (CallNumber, Fname, Lname), FOREIGN KEY (CallNumber) REFERENCES Title (CallNumber)); CREATE TABLE Member (MemNo NUMERIC (20) NOT NULL, DriverLicState VARCHAR (20) Driverlicno Varchar (40), FName Varchar (20), Mi Varchar (10), Lname Varchar (20), Address Varchar (25), Phonenumber Varchar (15), Primary Key (Memno); Create Table Hold (Memno Numeric (20) NOT NULL, CallNumber VARCHAR (40) NOT NULL, HoldDatetime DATETIME, PRIMARY KEY (MemNo, CallNumber), FOREIGN KEY (MemNo) REFERENCES Member (MemNo), FOREIGN KEY (CallNumber) REFERENCES Title (CallNumber)); CREATE TABLE Librarian SSN Numeric (20) Not NULL, NAME VARCHAR (80), Address Varchar (250), Salary Numeric (9, 2), Gnder Char (1), Birthday DateTime, Superssn Numeric (20), Section Numeric (20), PRIMARY Key (SSN), Foreign Key (SUPERSSN) References Librarian (SSN); Create Table Se (SECTNO NUMERIC (20) Not Null, Name Varchar (80), Headssn Numeric (20), Primary Key (SECTNO), Foreign Key ( HeadSSN) REFERENCES Librarian (SSN)); CREATE TABLE Dependent (LibSSN NUMERIC (20) NOT NULL, Name VARCHAR (40) NOT NULL, Birthday DATETIME, Kinship VARCHAR (40), PRIMARY KEY (LibSSN, Name), FOREIGN KEY (LibSSN References Librarian (SSN));
CREATE TABLE Book (Book_ID NUMERIC (20) NOT NULL, Edition VARCHAR (80), BorrowerMemNo NUMERIC (20), BorrowDueDatetime DATETIME, CallNumber VARCHAR (40), LibCheck NUMERIC (20), PRIMARY KEY (Book_ID), FOREIGN KEY (CallNumber) REFERENCES Title (CallNumber), FOREIGN KEY (BorrowerMemNo) REFERENCES Member (MemNo), FOREIGN KEY (LibCheck) REFERENCES Librarian (SSN)); INSERT INTO Title VALUES ( 'Call123', 'Iliad', 'ISBN123', '1997/01 / 01 ',' Home Publishing '); INSERT INTO TITLE VALUES (' Call124 ',' ODYSSEY ',' ISBN124 ',' 1997/01/01 ',' Home Publishing '); Insert Into Title Values (' Call125 ', 'Database Systems',' ISBN125 ',' 1999/01/01 ',' AWL '); Insert INTO TITLE VALUES (' Call126 ',' Financial Accounting ',' ISBN126 ',' 1997/01/01 ',' McGrawHill '); Insert INTO TITLE VALUES (' Call127 ',' Second World War ',' ISBN127 ',' 1986/05/01 ',' McGrawHill '); INSERT INTO TITLE VALUES (' Call128 ',' NetWorks ',' ISBN128 ',' 1986/05/01 ',' AWL '); Insert Into Title Values (' Call129, 'Pitt Roads', 'ISBN129', '1986/05/01', 'AWL'); Insert Into Member Value S (123, 'Pa', '123', 'John', '', 'Summers', '4615 Forbes Ave, Pittsburgh, PA 15213', '412-268-0001'); Insert Into Member Values (124, 'Ga', '124', 'Jon', '', 'Butterworth', '10 Fifth Ave, Atlanta, Ga 30332 ',' 404-894-0001 '); Insert Into Member Values (125,' Pa ', '125', 'Susan', 'B', 'Carlione', '
4600 Verona Road, Pittsburgh, PA 15217 ',' 412-200-0001 '); Insert Into Member Values (126,' NC ',' 126 ',' Mohammed ',' ',' Ismail ',' 250 Peachtree Street, Salem, NC 15213 ',' 421-268-0001 '); Insert Into Member Values (127,' Pa ',' 127, 'Asterio', '', 'Tanaka', '415 Craig Street, Pittsburgh, PA 15213 ',' 412-220-0001 '; Insert Into Author Values (' Call123 ',' Hello ',' ',' Homer '); Insert Into Author Values (' Call124 ',' Hello ',', 'Homer '); Insert Into Author Values (' Call125 ',' Jack ',' ',' Collins'); Insert Into Author Values ('Call126', 'Jack', '', 'Collins'); Insert Into Author Values 'Call127', 'Winston', '', 'Churchill'); Insert Into Author Values ('Call127', 'John', '', 'KEEGAN'); Insert Into Author Values ('Call128', 'Jeff', '', 'TANENBAUM'); Insert Into Author Values ('Call129,' Carlos', '', 'Tanaka'); INSERT INTO HOLD VALUES (123, 'Call123', '2000-10-10'); Insert INTO LIBRARIAN VALUES (201, 'Ashoka Savasere', '4615 Forbes Ave, Pittsburgh, PA 15213', 40000, 'F', '1972-06-02', NULL, 1); Insert in To Librarian Values (202, 'Alfred Watkins ",' 4615 Forbes Ave, Pittsburgh, PA 15213 ', 40000,' M ',' 1972-07-02 ', NULL, 1); Insert Into Librarian Values (203,' Yong -Chul oh ',' 4600 forbes Ave, Pittsburgh, PA 15213 ', 40000,' M, '1960-06-02', NULL, 1);
Insert Into Librarian Values (204, 'Shamkant Navathe', '4615 Forbes Ave, Pittsburgh, PA 15213', 40000, 'M', '1975-06-02', NULL, 2); Insert Into Book Values (123, ' 1 ', 123,' 2000-12-12 ',' Call123 ', 202); INSERT INTO BOOK VALUES (223,' 1 ', 125,' 2000-11-11 ',' Call123 ', 201); Insert Into Book Values (124, '1', 124, '2000-06-09', 'Call124', 201); Insert Into Book Values (224, '1', 125, '2000-11-11', 'Call124' , 201); INSERT INTO BOOK VALUES (125, '1', 125, '2000-11-11', 'Call125', 201); Insert Into Book Values (225, '1', Null, Null, 'Call125' , NULL); INSERT INTO BOOK VALUES (126, '1', 125, '2000-11-11', 'Call126', 201); Insert Into Book Values (226, '1', 124, '2000-06- 09, 'Call126', 202); Insert Into Book Values (326, '1', 124, '2000-06-09', 'Call126', 202); Insert Into Book Values (127, '1', NULL , NULL, 'CALL127', NULL; INSERT INTO BOOK VALUES (128, '1', 125, '2000-11-11', 'Call128', 201); Insert Into Book Values (228, '1', 126 , '2000-10-10', 'Call128', 202); INSERT INTO BOOK VALUES (129, '1', 123, ' 2000-12-12 ',' Call129 ', 202); Insert Into Book Values (229,' 1 ', 125,' 2000-12-12 ',' Call129 ', 202); Insert Into Section Values (1,' CheckOut ', 201); INSERT INTO Section VALUES (2,' Reference ', 204); ALTER TABLE LibrarianADD CONSTRAINT LibSection FOREIGN KEY (Section) REFERENCES Section (SectNo); INSERT INTO Dependent VALUES (203,' Luc Whang ',' 1998 -11-11 ',' Son '
); My answer Database2.sql:
/ ***Database2.sql written by Dragonshard 2005-3-28 22:11 *** /
/ * Question 1 * / SELECT NAME, YEARFROM TITLEWHER CALLNUMBER = Some (SELECT CALLNUMBER AUTHOR WHERE LNAME = 'churchill')
/ * Question 2 * / select namefrom titlewhere callnumber = Some (Select callnumber from book where borrowerMemno = Some (select memno from member where fname = 'jhon' or fname = 'susan'))
/ * Question 3 * / SELECT Fname, Lname, DriverLicNoFROM MemberWHERE DriverLicNo = SOME (SELECT BorrowerMemNo FROM Book WHERE CallNumber = SOME (SELECT CallNumber FROM Title WHERE Name = 'Iliad')) AND DriverLicNo = SOME (SELECT BorrowerMemNo FROM Book WHERE CallNumber = Some (Select CallNumber from Title Where Name = 'ODYSSEY')))
/ * Question 4 * / SELECT Fname, LnameFROM MemberWhere MemNo IN (SELECT BorrowerMemNo FROM (SELECT BorrowerMemNo, CallNumber FROM Book WHERE CallNumber IN (SELECT CallNumber FROM Author WHERE Lname = 'Collins') UNION SELECT BorrowerMemNo, CallNumber FROM Book WHERE CallNumber IN (SELECT CallNumber FROM Author WHERE Lname = 'Collins')) AS MidTab GROUP BY BorrowerMemNo HAVING COUNT (BorrowerMemNo) = (SELECT COUNT (Lname) FROM Author WHERE Lname = 'Collins')) / * question 5 * / SELECT PhoneNumberFROM MemberWhere Memno in (SELECT BORROWERMNO From book where callnumber = Some (select callnumber from author where lname = 'tanenbaum')))
/ * Question 6 * / SELECT Book.Book_ID, Member.Fname, Member.Lname, Member.MemNoFROM Member, BookWHERE Member.MemNo = Book.BorrowerMemNoGROUP BY Book.Book_ID, Member.Fname, Member.Lname, Member.MemNoHAVING ( Select Count (Book.borrowermemno) from Book Where Me MEMNO = Book.borrowerMemno> 3ORDER BY Count (Book.Book_ID) DESC
/ * Item 7 * / SELECT Member.Fname, Member.Lname, Member.MemNoFROM MemberWHERE Member.MemNo NOT IN (SELECT Member.MemNo FROM Member, Book WHERE Member.MemNo = Book.BorrowerMemNo GROUP BY Member.MemNo HAVING COUNT ( Book.BorrowerMemNo)> = 1) / * question 8 * / SELECT Member.FnameFROM MemberWHERE Member.MemNo NOT IN (SELECT Book.BorrowerMemNo FROM Book WHERE Book.CallNumber = (SELECT Title.CallNumber FROM title WHERE Title.Name = ' Pitt Roads')) And Phonenumber Like '412%'