If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > New Members & Introductions > Some relational algebra solutions I'd like to discuss

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-01-10, 14:11
Saborion Saborion is offline
Registered User
 
Join Date: Sep 2010
Posts: 2
Some relational algebra solutions I'd like to discuss

Hi,

I just began a class in database "stuff". Some of the early problems are regarding relational algebra. I think I have solved them all, but would like to list two of the problems (and my solutions) in the hope of getting some input on efficiency for the DBMS, easy of "readiness" for humans and so on.

I want to make it clear that I'm not here for others to my assignments. As I said above, I already have solutions for all problems. They may not be correct, but as far as I know they are. I'm more interested in getting a tiny bit better understanding on how to "solve" these kind of problems in an efficient and easy to read manner.

First problem:
In which divisions do all employee's make less than their manager?
Two tables of importance:
Employee ((name), salary, manager, division)
Division ((division), floor)

My solution:
I find all divisions that has at least one employee that makes more than his/her manager and save them in a new table, which I then subtract from the Division table.
S <-- SELECT Employee.manager = R.name ^ Employee.salary > R.salary (Employee X (P)R (Employee))
PROJECTION division (Division) - PROJECTION division (S)

I hope that is clear enough. (R) is the rename operator.
Is my solution correct? Is this a good way to approach this problem? I am a bit curious about doing a Cartesian product on the same table like that "just to find the manager", since I get this feeling it can be ugly in case the table is big?
-----------------------------------------------

Problem 2:
Which companies deliver items to more than one floor?
Two tables of importance:
Storage ((company, division, itemnr), volume)
Division ((division), floor)

My solution:
Do a natural join on Storage and Division, group by company and do a distinct count on floor. Save in a new table, do a selection on it where count > 1 and finally a projection to get the name of the companies.

(P)R (company, count) company G COUNT-DISTINCT floor (Storage X Division)
PROJECTION company (SELECTION count > 1 (R))

Good approach? (R) is the rename operator and G is the operator used for aggregate functions.
Reply With Quote
  #2 (permalink)  
Old 09-01-10, 16:09
simonwa simonwa is offline
Registered User
 
Join Date: Sep 2010
Location: fl
Posts: 1
Im good with algrebra but these problems seem to require additional data.
So are you asking if the formula for the problem is correct?
Reply With Quote
  #3 (permalink)  
Old 09-02-10, 00:42
Saborion Saborion is offline
Registered User
 
Join Date: Sep 2010
Posts: 2
Additional data...

The tables we have at our disposal are
Employee ((name), salary, manager, division)
Sales ((division, itemnr), volume)
Supplier ((company, adress)
Storage ((company, division, itemnr), volume)
Division ((division), floor)
Item ((itemnr), type)

What I was hoping for, ideallly, was something along the lines of "Yes, your solutions work. However, if you write problem one like this, xxxx, it would be easier to read". The fact that you said they require additional data means I haven't fully understood this stuff yet.

Last edited by Saborion; 09-02-10 at 00:56.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On