Results 1 to 3 of 3
  1. #1
    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.

  2. #2
    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?

  3. #3
    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 01:56.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •