Re: relational algebra - grouping and max question
Date: 5 Jul 2002 21:11:58 +0200
Message-ID: <3d25ef7e$1_at_news.uia.ac.be>
In article <TllV8.660$cpF.434_at_news01.bloor.is.net.cable.rogers.com>,
Zeb Fropiaz <aik__1_at_hotmail.com> wrote:
>Say, I grouped a table with respect to certain attribute, and I counted the
>number of id's in each group. Now I need to do something to the group which
>had the maximum number of id's. How would I access that group in relational
>algebra?
I'll give you a hint. Suppose I have a relation R(a,b) and I want the 'a' with the largest 'b'. For simplicity I will take the algebra for unlabeled columns, i.e., columns are ordered and represented by their number. First we take the Cartesian prodoct of R with itself:
S := R TIMES R Then we select those tuples where the first 'b' column (col. #2) is smaller than the second 'b' column (col. #4).
T := S WHERE #2 < #4
Then we project on the first column.
U := T [ #1 ]
This gives you all 'a's for which there is another 'a' with a bigger 'b', i.e., all 'a's that don't have the maximal 'b'. You're on your own from here.
Good luck,
- Jan Hidders