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.