sql->关系代数
如何将其转换为关系代数树?
逻辑步骤是什么?我首先需要转换为关系代数吗?或者我可以直接从 sql 转到树吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会首先转换为关系代数,然后转换为树。
看,
SELECT
子句只需要三个字段。这是一个投影
。FROM
子句具有三个关系。这是一个笛卡尔积
。WHERE
子句给出了一堆选择
。这是在转换为树之前帮助转换为关系代数的部分。我不知道你在课堂上使用什么符号,但你可能想要一些具有一般形式
或投影的选择的东西......由叉积产生的东西。
请注意,根据您的讲师的挑剔程度,您可能需要重命名字段。由于 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 aprojection
.The
FROM
clause has three relations. That's aCartesian product
.The
WHERE
clause gives a bunch ofselection
s. 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
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.
该 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.