将SQL查询转换为Relational Algebra

时间:2016-03-22 00:37:41

标签: sql relational-algebra

我必须以特定方式将SQL查询转换为关系代数,但我不确定我的答案是否正确。

数据库

Students: (studentID, firstname, familyname, address, borough)
Entries: (studentID, examID< result)
Exams: (examID, examName, qualification, board, date)

SQL查询

SELECT studentID
FROM Students s, Entries e, Exams x
WHERE s.studentID = e.studentID AND e.examID = x.examID AND 
s.borough='Haringey' AND e.result = 'pass' AND x.examName='Latin'

我必须在关系代数中重新表达此查询,其中在表格被选择运算符缩小后对表格执行连接

我的回答

PROJECT studentID (SELECT s.borough ='Haringey'(学生))EQUI​​JOIN s.studentID = e.studentID ((SELECT e.result ='pass'(Entries))EQUI​​JOIN e.examID = x.examID (SELECT x.examName ='Latin'(考试)))

1 个答案:

答案 0 :(得分:1)

您的查询是正确的。您已正确“推送”所有选择操作。请注意,您还可以将每个选择的结果投影到以下运算符所需的最小数量的属性。