我如何找到MAX与关系代数? [英] How can I find MAX with relational algebra?

查看:333
本文介绍了我如何找到MAX与关系代数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据库,如何使用关系代数找到MAX?

解决方案

假设你有一个关系一个单一的属性,'a'(减少一个更复杂的关系,这是一个简单的任务在关系代数,我相信你有这么远),所以现在你想找到A的最大值。

$一个方法是找到A与自身的叉积,确保重命名'a',以便您的新关系具有不同名称的属性。例如:



(重命名'a'为'a1')X(重命名'a'为'a2')


$ b b

现在选择'a1'< 'a2',结果关系将具有除最大值之外的所有值。要获取最大值,只需找出原始关系之间的差异:

  A x A  - (选择'a1'<'a2 ')((重命名'a'为'a1')(A)x(重命名'a'为'a2')(A))

然后使用项目运算符减少到一个列,如Tobi Lehman在下面的注释中建议的那样。



我为这个符号道歉,我不知道如何获得带有下标的关系代数符号等,以显示在这个文本框中。


Working with databases, how can I find MAX using relational algebra?

解决方案

Assuming you have a relation, A, with a single attribute, 'a' (reducing a more complex relation to this is a simple task in relational algebra, I'm sure you got this far), so now you want to find the maximum value in A.

One way to do it is to find the cross product of A with itself, be sure to rename 'a' so your new relation has attributes with distinct names. for example:

(rename 'a' as 'a1') X (rename 'a' as 'a2')

now select 'a1' < 'a2', the resulting relation will have all values except the maximum. To get the max simply find the difference between your original relation:

A x A - (select 'a1' < 'a2') ((rename 'a' as 'a1')(A) x (rename 'a' as 'a2')(A))

Then use the project operator to reduce down to a single column as Tobi Lehman suggests in the comment below.

I apologize for the notation, I don't know how to get the relational algebra symbols with subscripts etc to show in this text-box.

这篇关于我如何找到MAX与关系代数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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