Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: relational algebra - grouping and max question

Re: relational algebra - grouping and max question

From: Jan.Hidders <hidders_at_hcoss.uia.ac.be>
Date: 5 Jul 2002 21:11:58 +0200
Message-ID: <3d25ef7e$1@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,

Received on Fri Jul 05 2002 - 14:11:58 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US