dbTalk Databases Forums  

Relational Algebra Expression

comp.databases.theory comp.databases.theory


Discuss Relational Algebra Expression in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #81  
Old   
Bob Badour
 
Posts: n/a

Default Re: Relational Algebra Expression - 02-09-2008 , 09:10 PM






JOG wrote:

Quote:
On Feb 10, 12:19 am, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

JOG wrote:

On Feb 9, 10:30 pm, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

JOG wrote:

On Feb 9, 4:59 pm, gamehack <gameh... (AT) gmail (DOT) com> wrote:

On Feb 9, 4:47 pm, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

gamehack wrote:
[snip]

What I'm trying to do is extract all the years where we have more than
1 relation for the year. For the sample table, we need to get:
1999
2001

I tried to do in a couple of ways but I couldn't. I tried using a
projection on Year so that I can remove duplicates but then I can't
just use difference because the new relations are not compatible. Any
hints are greatly appreciated.

Equijoin on year and inequality theta-join on name project on year.

Hi,

I can't really understand what this means - can you bracket it so I
can see the results of each operation?

Thanks very much,
g

Well Bob gave you everything you needed, but I guess you're learning
the stuff at the moment (coursework?) so lets break down his
instructions:

1) EQUIJOIN R with itself (renamed B) where Year = B.Year
2) RESTRICT where Name != B.Name
3) PROJECT on Year

In terms of whats going on:
1 - Gives you a relation of any two rows with the same year
concatenated together
2 - Removes the years that were joined with themselves in 1.
3 - Gets rid of all attributes apart from Year. Because a relation is
a set this also eliminates any duplicates, and voila you are left with
the years that appeared more than once.

Note if you use SQL it can allow duplicates (which is of course
particularly brain-dead given a relation is a set), so you have to
specify you want distinct tuples:

SELECT DISTINCT Year FROM R, R as B
WHERE R.Year = B.Year AND R.Name != B.Name

He mentioned relational algebra. I figured he would have to rename
attributes instead. In D, I would use "rename all but year prepending
'other_'" or something similar. I don't think that 'B.' crap flies with
relations.

You see what being faced with SQL every day does to someone!? It
addles the brain. I should sue.

Out of interest, here is an equivalent procedural solution to the OP's
problem:

std::set<int> results;
std::set<row>::iterator i;
std::set<row>::iterator j;

for(i = R.begin(); i != R.end(); ++i)
{
for(j = i + 1; j != R.end(); ++j)
{
if ( (*i).year == (*j).year)
{
results.insert((*i).year);
break;
}
}
}

nice isn't it

It would be just peachy keen if it didn't have a bug.

Bugs!? Clean as a whistle I tell you.
Why, so you are right! It would be just peachy keen if it didn't look so
much like it had a bug then.


Reply With Quote
  #82  
Old   
Bob Badour
 
Posts: n/a

Default Re: Relational Algebra Expression - 02-09-2008 , 09:10 PM






JOG wrote:

Quote:
On Feb 10, 12:19 am, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

JOG wrote:

On Feb 9, 10:30 pm, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

JOG wrote:

On Feb 9, 4:59 pm, gamehack <gameh... (AT) gmail (DOT) com> wrote:

On Feb 9, 4:47 pm, Bob Badour <bbad... (AT) pei (DOT) sympatico.ca> wrote:

gamehack wrote:
[snip]

What I'm trying to do is extract all the years where we have more than
1 relation for the year. For the sample table, we need to get:
1999
2001

I tried to do in a couple of ways but I couldn't. I tried using a
projection on Year so that I can remove duplicates but then I can't
just use difference because the new relations are not compatible. Any
hints are greatly appreciated.

Equijoin on year and inequality theta-join on name project on year.

Hi,

I can't really understand what this means - can you bracket it so I
can see the results of each operation?

Thanks very much,
g

Well Bob gave you everything you needed, but I guess you're learning
the stuff at the moment (coursework?) so lets break down his
instructions:

1) EQUIJOIN R with itself (renamed B) where Year = B.Year
2) RESTRICT where Name != B.Name
3) PROJECT on Year

In terms of whats going on:
1 - Gives you a relation of any two rows with the same year
concatenated together
2 - Removes the years that were joined with themselves in 1.
3 - Gets rid of all attributes apart from Year. Because a relation is
a set this also eliminates any duplicates, and voila you are left with
the years that appeared more than once.

Note if you use SQL it can allow duplicates (which is of course
particularly brain-dead given a relation is a set), so you have to
specify you want distinct tuples:

SELECT DISTINCT Year FROM R, R as B
WHERE R.Year = B.Year AND R.Name != B.Name

He mentioned relational algebra. I figured he would have to rename
attributes instead. In D, I would use "rename all but year prepending
'other_'" or something similar. I don't think that 'B.' crap flies with
relations.

You see what being faced with SQL every day does to someone!? It
addles the brain. I should sue.

Out of interest, here is an equivalent procedural solution to the OP's
problem:

std::set<int> results;
std::set<row>::iterator i;
std::set<row>::iterator j;

for(i = R.begin(); i != R.end(); ++i)
{
for(j = i + 1; j != R.end(); ++j)
{
if ( (*i).year == (*j).year)
{
results.insert((*i).year);
break;
}
}
}

nice isn't it

It would be just peachy keen if it didn't have a bug.

Bugs!? Clean as a whistle I tell you.
Why, so you are right! It would be just peachy keen if it didn't look so
much like it had a bug then.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.