relational-algebra - 理解关系代数中的除法

标签 relational-algebra relational-division

我在理解这张关于关系代数除法的幻灯片时遇到了一些困难。我做了一些研究,很多人提到On Making Relational Algebra Comprehensible by Lester I McCann.我无法理解其中一张幻灯片(幻灯片 13)。我基本上重新创建了下面的幻灯片。

Query: Find the sno value of the suppliers that supply all parts of weight equal to 17.

Relation P

+-------------------------------+
| pno pname color weight city   |
+-------------------------------+
| P1  Nut   Red   12.0   London |
| . . . . . . . . . . . . . . . |
| P6  Cog   Red   19.0   London |
+-------------------------------+

Relation SPJ

+-------------------------+
| sno pno jno qty         |
+-------------------------+
| S1  P1  J1  200         |
| . . . . . . . . . . . . |
| S5  P6  J4  500         |
+-------------------------+

我知道我需要以下架构。关系 A 投影 sno、pno 列表。关系 B 告诉您哪个 pno 等于 17 权重。

α (sno, pno)
β (pno) 
α ← π sno,pno (SPJ)
β ← π pno (σ weight=17 (P))

Result:

Relation α

+---------+
| sno pno |
+---------+
| S1 P1   |
| S2 P3   |
| S2 P5   |
| S3 P3   |
| S3 P4   |
| S4 P6   |
| S5 P1   |
| S5 P2   |
| S5 P3   |
| S5 P4   |
| S5 P5   |
| S5 P6   |
+---------+

Relation β:

+-----+
| pno |
+-----+
| p2  |
| p3  |
+-----+

但是幻灯片接着说:

Find the values that do not belong in the answer, and remove them from the list of possible answers.

In our P–SPJ example, the list of possible answers is just the available sno values in α:

+-----+
| sno |
+-----+
| S1  |
| S2  |
| S3  |
| S4  |
| S5  |
+-----+

这就是我被困住的地方。他在示例中说“P - SPJ”,但如果我这样做,我就无法得到上面的关系。我认为 P - SPJ 都不可能吗?根据数据库系统第一类(class),当我们对关系应用差异操作时,两个表需要具有具有相同属性集的模式(P和SPJ没有)?

如果有人能指出我正确的方向,那就太好了,谢谢!我有本书数据库系统第一类(class),第 4 章,它教授关系代数,但不幸的是不教授除法(我偶然发现并想学习)。

最佳答案

Find the values that do not belong in the answer, and remove them from the list of possible answers.

当他们说“查找不属于答案的值”时,这是他们稍后会做的事情。 “不属于的值”的关系将是 π sno (δ) .

当他们说“并将它们从可能答案列表中删除”时,他们的意思是答案是他们最终在接下来找到的“可能答案列表”关系之间所做的关系差异 & π sno (δ)之后他们发现了。

In our P–SPJ example, the list of possible answers is just the available sno values in α:

当他们说“在我们的 P-SPJ 示例中,...”时,他们的意思只是“在我们涉及 P 和 SPJ 关系的示例中,...”。他们正在使用破折号;他们没有使用减号来表示关系差异。他们接下来计算并显示的是“可能答案列表”关系 π sno (α) .

(最后他们得到了答案,即 π sno (α) - π sno (δ) 。)

关于relational-algebra - 理解关系代数中的除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53824083/

相关文章:

mysql - 在不同的行上选择满足不同条件的值?

sql - 将键值列分组为每组一行,每个键列

mysql - IN 对于许多元素

SQL 查询(在 SQL、关系代数和元组关系演算中)

sql - 是否有任何开源查询语言不可知关系存储引擎?

sql - 这个投影会返回什么?

sql - 关系代数 - 恰好找到两个值

sql - 如何在 SQL Server 中实现 DIVIDE 操作的关系等价物

mysql - 如何编写一个返回所有玩家姓名的 SQL 查询...?

sql - 对WITH 子句中的表使用 INTERSECT