sql->关系代数

发布于 2024-11-10 01:35:15 字数 137 浏览 5 评论 0原文

在此处输入图像描述

如何将其转换为关系代数树?

逻辑步骤是什么?我首先需要转换为关系代数吗?或者我可以直接从 sql 转到树吗?

enter image description here

How do I convert this to relational algebra tree?

What are the logical steps? Do I first need to convert to relational algebra? Or can I go straight from sql to tree?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水溶 2024-11-17 01:35:15

我会首先转换为关系代数,然后转换为树。

看,SELECT 子句只需要三个字段。这是一个投影

FROM 子句具有三个关系。这是一个笛卡尔积

WHERE 子句给出了一堆选择。这是在转换为树之前帮助转换为关系代数的部分。

我不知道你在课堂上使用什么符号,但你可能想要一些具有一般形式

projection((things-you-want), selection((criteria), selection((criteria),
  selection((criteria), aXbXc))))

或投影的选择的东西......由叉积产生的东西。

请注意,根据您的讲师的挑剔程度,您可能需要重命名字段。由于 Show 和 Seat 都具有 showNo 作为属性,因此在为它们提供唯一名称之前可能不允许您进行叉积(替代规则,属性由隐式关系名称前缀唯一标识)。

此外,根据课程的目的,您可以交换其中一些操作。您可以在 Booking 上进行选择,然后再采用叉积作为限制日期范围的手段。最终结果将是相同的。

不管怎样,从 sql 到关系代数再到树真的需要那么多额外的工作吗?我毫不怀疑,通过练习,您可以跳过中间步骤。不过,既然你首先提出了这个问题,我建议你走走过场。还记得初中数学老师对组合简单术语的“展示你的作品”的要求吗?这一要求在高中就消失了?同样的规则也适用于此。我是作为一名计算机作业的前评分者这么说的。

I would first convert to relational algebra, then convert to the tree.

Look, the SELECT clause only wants three fields. That's a projection.

The FROM clause has three relations. That's a Cartesian product.

The WHERE clause gives a bunch of selections. This is the part where it helps to convert to relational algebra before converting to a tree.

I have no idea what notation you use in class, but you probably want something that has a general form of

projection((things-you-want), selection((criteria), selection((criteria),
  selection((criteria), aXbXc))))

or projection of selection of selection of ... stuff resulting from cross products.

Note, depending on how picky your instructor is, you may have to rename fields. Since both Show and Seat have showNo as an attribute, you may not be allowed to take the cross product before giving them unique names (alternative rules, attributes are uniquely identified by an implicit relation name prefix).

Furthermore, depending on the purpose of the lesson, you may commute some of these operations. You can do a selection on Booking before taking the cross product as a means of restricting the date range. The end results will be equivalent.

Anyway, is it really that much extra work to go from sql to relational algebra to tree? I have no doubt that with practice, you could skip the intermediate step. However, since you asked the question in the first place, I would suggest going through the motions. Remember the "show your work" requirement from junior high math teachers for the combining of simple terms that went away in high school? Same rule applies here. I say this as a former grader of CS assignments.

生来就爱笑 2024-11-17 01:35:15

该 SQL 查询的结果不是关系,因此它在 RA 中没有完全相同的结果。您可以尝试创建添加了 DISTINCT 的同一 SQL 查询的 RA 版本。

The result of that SQL query is not a relation so it has no exact equivalent in the RA. You could try creating an RA version of the same SQL query with DISTINCT added.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文