relational algebra of the query

2019-09-21 19:11发布

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.

2条回答
三岁会撩人
2楼-- · 2019-09-21 19:33

this may be the correct answer

ΠCno(PRE-REQ) - ΠCno( PRE-REQ - (COMPLETED ⋈COMPLETED.Cno=pre-Cno ^ student_no=2310 PRE-REQ ))

查看更多
一夜七次
3楼-- · 2019-09-21 19:45

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.)

查看更多
登录 后发表回答