注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
only allow things like select, project, join, cross, diff, union, rename,
===========
假如我只有一个relation A,里面就1 attribute called n, 里面是一列数字,假如是k个数字
用relational algebra找出里面的最大(或者最小)
我的做法是
rename n 成m,叫新relations B
A cross B 就是个方形矩阵
从里面select m>n的,这样就只保留了矩阵的一个三角,有k*(k-1)/2个数字pair,假定这个新relation我们叫它C
select n from C and rename it X, call this new relation Y
select m from C and rename call it X, call this new relation Z
then Y diff Z is the max...
我知道答案是对的,但是写起来复杂无比
有简单办法不? |