问题
Consider the following relational database schemes:
COURSES (Cno,name)
PRE-REQ(Cno, pre-Cno)
COMPLETED (student_no, Cno)
COURSES gives the number and name of all the available courses.
PRE-REQ gives the information about which courses are pre-requisites for a given course.
COMPLETED indicates what courses have been completed by students
Express the following using relational algebra:
List all the courses for which a student with student_no = 2310 has completed all the pre-requisites.
the question can be solved by SQL query but unable to derive equivalent relational algebra.
回答1:
Here's an answer in the TUTORIAL D variant of RA:
WITH { COMPL_2310 := (COMPLETED WHERE student_no = '2310')
{ Cno } RENAME { Cno AS pre-Cno }
}
COURSES WHERE ( ( RELATION{ TUPLE{*} } JOIN PRE_REQ ){ pre-Cno }
⊆
COMPL_2310
)
(This uses some of the recently introduced syntactic sugar and alternative syntax compared to Date & Darwen's textbooks.)
回答2:
this may be the correct answer
ΠCno(PRE-REQ) - ΠCno( PRE-REQ - (COMPLETED ⋈COMPLETED.Cno=pre-Cno ^ student_no=2310 PRE-REQ ))
来源:https://stackoverflow.com/questions/45379328/relational-algebra-of-the-query