relational algebra of the query

只谈情不闲聊 提交于 2019-12-14 00:08:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!