2012-03-26 2 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 식을 사용합니다. 그것은 내가 관계 대수를 사용했다 이후 년 정도되었습니다

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

하지만, 그것은 당신의 사전 조건이이 인 (무엇이든지 할 것이다 :

+0

당신의 대답 중 일부는'DateLoaned' 대신에'DateReturned' 속성을 사용해야합니다. –

+0

1.1에 대한 답. 불균형 괄호가 있습니다 (즉, 닫는 괄호가 누락 됨). SQL에서'= "NULL"및'<> "NULL"'은 정수 열에 의도 한대로 작동하지 않지만 목적에 맞는 것일 수 있습니다. – onedaywhen

답변

1

교수는 그것을 할 방법을 말했다 선 다음에 당신을 위해 작업) :

LIKE %James Stewart% 

SQL 문은 다음과 같이 보일 것입니다 :

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

여러분의 연구에서 관계형 대수학은 SQL의 함수를 다루지 않고 단지 수학적 측면만을 살펴 봅니다.

관련 문제