2012-03-26 63 views
0

嗨有人可以請驗證我的工作。林不知道如果我正確地做任何這一點,並將不勝感激任何幫助。我不允許使用領結運算符。謝謝。關係代數檢查錯誤

問:

Books (ISBN, Title, Authors, Publisher, Ed, Year, Genre) 
Patron (MemberNumber, FirstName, LastName, AddressLn1, AddressLn2, City, State, Zipcode) 
Loan (MemberNumber,ISBN,DateLoaned,DateDue, DateReturned) 

Business Logic 
• You may assume that the library only has one copy of each book. 
• Each book may have many authors. If a particular book has multiple authors, they are listed as a comma separated string. You may assume that the same author always uses the same exact name and no two authors will have the same name. 
• Year is stored as an integer. 
• DateLoaned, DateDue, and DateReturned are stored as a date. 
• When a book is initially lent out, DateReturned is set to be NULL, upon its return, the value is updated. 

1.1. Find all books that were loaned out after 12/22/2012. Show the ISBN, Title, and DateDue. 
1.2. Find all library patrons who have borrowed a book titled "Database Systems". Show their FirstName, LastName, and DateLoaned. 
1.3. Find all books that were ever loaned out. Display the ISBN. 
1.4. Find all books returned before 12/22/2012. Display the ISBN. 
1.5. Find all books returned on or after 12/22/2012. Display the ISBN. 
1.6. Find all books returned either (before 12/22/2012) or (on or after 12/22/2012) Display the ISBN. 
1.7. In 1 sentence explain the difference between 1.3 and 1.6. 
1.8. Find all patrons who have never borrowed a book. 
1.9. Find all books with Genre "Mystery" that have NEVER been loaned out. 
1.10. Create a new attribute ImportantDates. A date is important if it is in the Loan relation either as a DateLoaned or a DateDue. Display ImportantDates. 
1.11. Find all library patrons who have borrowed a book with an author "James Stewart". You may use the expression LIKE "%James Stewart%" in your Relational Algebra. 
1.12. Find all library patrons who have never borrowed a book with an author "James Stewart". You may use the expression LIKE "%James Stewart%" in your Relational Algebra. 
1.13. Find all library patrons who have only borrowed a book with an author "James Stewart". If they have ever borrowed a book without the author "James Stewart" they should be excluded. You may use the expression LIKE "%James Stewart%" in your Relational Algebra.  

答:

1.1) πISBN,TITLE,DATEDUE(σDATELOANED > 12222012 AND BOOKS.ISBN = LOAN.ISBN(LOAN X BOOKS) 
1.2) πFIRSTNAME,LASTNAME,DATELOANED(σTITLE = "DATABASE SYSTEMS" AND BOOKS.ISBN = LOAN.ISBN AND PATRON.MEMBERNUMBER = LOAN.MEMBERNUMBER(BOOKS X PATRON X LOAN)) 
1.3) πISBN(σDATELOANED <> "NULL" AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS)) 
1.4) πISBN(σDATELOANED < 12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS)) 
1.5) πISBN(σDATELOANED >= 12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS)) 
1.6) πISBN(σDATELOANED >= 12222012 OR DATELOANED <12222012 AND BOOK.ISBN = LOAN.ISBN(LOAN X BOOKS)) 
1.7) 1.3 AND 1.6 are the same as they both find books that have been loaned. 
1.8) σDATELOANED = "NULL" AND PATRON.MEMBERNUMBER = LOAN.MEMBERNUMBER(LOAN X PATRON) 
1.9) σGENRE = "MYSTERY" AND BOOKS.ISBN = LOAN.ISBN AND DATELOANED = "NULL" 
1.10) LOAN(DATELOANED,DATEDUE) -> IMPORTANTDATE 

能否請您給我的例子無論是1.11,1.12,或1.13,因爲我有多麼不知道使用LIKE表達式。

+0

在我看來,你的一些答案應該是使用'DateReturned'屬性而不是'DateLoaned'。 – 2012-03-26 20:21:54

+0

你的答案爲1.1。有不平衡的parens(即錯過右括號)。在SQL中,'=「NULL」'和'<>「NULL」'不會像整數列那樣工作,但可能適合您的目的。 – onedaywhen 2012-03-27 07:10:50

回答

1

教授告訴你如何做到這一點:

You may use the expression LIKE "%James Stewart%" in your Relational Algebra. 

,迄今已近一年,因爲我不得不使用關係代數,但是這將是無論你的先決條件是(這是一個其次是線任務,爲您):

LIKE %James Stewart% 

的SQL語句會是這個樣子:

Select * from patrons p where Books.author LIKE %James Stewart% 

你會發現在你的學習中,關係代數不涉及SQL的函數,它只是看着事物的純數學方面。