使用关系代数编写以下查询 [英] Writing the following query using relational algebra

查看:139
本文介绍了使用关系代数编写以下查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用关系代数编写以下查询:

I am trying to write the following query using the relational algebra:

"Find the names of sailors who reserved a red or a green boat"

这里是我的解决方案:

Here is my solution:

但这本书给出了以下解决方案:

But the book gives the following solution:

另一个等效解决方案by book:

And another equivalent solution given by book:

End here is the related tables:

End here is the related tables:

我的问题是,我们不能在选择运算符中使用或符号(V)吗?我的解决方案是否错误?为什么我们需要重命名运算符?

My question is, can't we use the "or" symbol (V) in selection operator? Is my solution wrong? Why do we need renaming operator?

感谢

推荐答案

关于限制:

您的书/老师似乎走的原则是限制条件只能是非常基本的。在关于 http://en.wikipedia.org/wiki/Selection_的维基文章%28relational_algebra%29 (至少一个引用的属性,另一个属性或常量值,只涉及一个比较运算符,不允许其他操作符调用,如SIN(angle attr)或MONTH(datetime attr)或.. 。)。

Your book/teacher seems to go by the principle that restriction conditions can only be "very basic". In the sense as the wiki article on http://en.wikipedia.org/wiki/Selection_%28relational_algebra%29 (at least one attribute referenced, one other attribute or constant value, only one single comparison operator involved, no other operator invocations allowed such as SIN(angle attr) or MONTH(datetime attr) or ...).

但是这种限制(在限制条件上)是不必要的。关于 http://en.wikipedia.org/的关系代数的Wiki文章wiki / Relational_algebra#Selection_.28.CF.83.29 明确说明...是一个命题公式,由...和逻辑运算符AND,OR,NOT ...组成。

But that restriction (on the restrict condition) is unnecessary. The wiki article about relational algebra on http://en.wikipedia.org/wiki/Relational_algebra#Selection_.28.CF.83.29 says explicitly "... is a propositional formula that consists of ... and the logical operators AND,OR,NOT ...".

对于重命名:

关系代数中的RENAME运算符用于产生一个关系值,

The RENAME operator in relational algebra is used to yield a relation value that differs from the input only in that certain attributes have "changed name".

您的图书/教师显然使用名为重命名的运算符分配名称

Your book/teacher apparently uses an operator called "rename" to assign a name to some specified relational expression (a UNION in your example). That isn't even an algebraic operation !!!

(虽然这是一个有效和有用的想法在语言设计中,为用户设计一个可能性 ,那么他可以随后仅使用分配的名称来引用,这是语言设计的问题,而不是关系代数!)

(While it is a valid and useful idea in language design to devise a possibility for the user to have "named expressions", that he can subsequently reference using just the assigned name, this is a matter of language design, not of relational algebra !)

这篇关于使用关系代数编写以下查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆