使用关系代数的列之间的最大差异

发布于 2025-01-02 21:43:03 字数 187 浏览 1 评论 0原文

是否可以获得两列之间的最大差异(例如开始和结束权重)?

现在我倾向于不,因为这需要一个新列,其中每行的两列之间存在差异,然后取最大值。按照我最初的意图进行操作也不起作用,因为在选择操作的条件下不允许算术运算(例如不允许 SIGMA (c1 - c2 < c3 - c4)(Table))。

披露:这是家庭作业问题的一部分。

Is it possible to obtain the maximum difference between two columns (for example starting and ending weights)?

Right now I'm leaning towards no as this would require a new column with the difference between the two columns for each row, then taking the max of that. Doing it the way I orginally intended doesn't work either since arithmetic operations are not allowed in the conditions of select operations (e.g. SIGMA (c1 - c2 < c3 - c4)(Table) is not allowed).

Disclosure: this is part of a homework question.

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

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

发布评论

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

评论(2

小梨窩很甜 2025-01-09 21:43:03

它可以完全按照您计划的方式完成,但您需要为此进行广义投影。广义投影是运算符

Π(E1, E2,..., En)R

,其中 R 是关系,E1...En 是 a⊕b 形式的表达式,其中 a 和 b 是 R 的属性或常量,⊕ 是它们之间的任意二元运算符。结果是与属性 E1...En 的关系。

这将允许您将差异投影到一个新的关系 (R' := Π(xy)R) 中,然后按照您的计划找到其最大值。

如果我们不允许使用广义投影,那么我认为我们没有办法实际从另一个属性中减去一个属性,或者实际从中计算任何内容,因为投影的定义只允许属性名称,而选择的定义允许仅 aθb 形式的表达式,其中 a 和 b 是属性或常量,θ 是二元关系运算符(这在其方式上是合乎逻辑的,因为如果我们有一个关系 R(X,Y),那么我们不知道X 的类型或Y,使得对它们的操作变得毫无意义)。

我认为广义投影是关系代数的一个很好的扩展。显然,它在现实生活中非常有用,甚至可以从更科学的角度来捍卫它:如果我们允许对“X > 50”之类的值使用二元条件运算符,那么我们已经对类型做出了假设,从而得出一点没有实际意义。不过,你的导师可能不同意。

It can be done, exactly in the way you planned, but you need generalized projection for that. The generalized projection is the operator

Π(E1, E2,..., En)R

where R is a relation, and E1...En are expressions in the form a⊕b, where a and b are attributes of R or constants, and ⊕ is an arbitrary binary operator between them. The result is a relation with attributes E1...En.

This would allow you to project the differences into a new relation (R' := Π(x-y)R), then find the maximum on that, just as you planned.

If we're not allowed to use generalized projection, then I think we have no means to actually subtract an attribute from another, or to actually calculate anything from them, as the definition of projection allow only attribute names, and the definition of selection allow only expressions of the form aθb where a and b are attributes or constants and θ is a binary relational operator (this is logical, in its way, because if we have a relation R(X,Y), then we have no idea about the type of X or Y, making operations on them quite meaningless).

I think generalized projection is a great extension to relational algebra. It's obviously immensely useful in real life, and it can be defended even from a more scientific point of view: if we allow binary conditional operators on the values like "X > 50", then we made assumptions on the type already, rendering that point kind of moot. Your instructor may disagree, though.

蘸点软妹酱 2025-01-09 21:43:03

如果您希望在现实世界中执行此操作,则应该能够使用子查询(或视图,这相当于同一件事)来执行此操作,例如:

select max (diff) from (
    select high - low as diff from blah blah blah
)

这是否适用于关系代数的抽象世界,我不能说。我太忙于解决那些该死的现实问题了:-)

If you're looking to do this in the real world, you should be able to do this with a subquery (or a view, which amounts to much the same thing), something like:

select max (diff) from (
    select high - low as diff from blah blah blah
)

Whether this applies to the abstract world of relational algebra, I couldn't say. I'm too busy fixing those damn real-world problems :-)

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