sql - How can I find all columns A whose subcategories B are all related to the same column C? -


I am trying to understand relational algebra better and I'm having trouble solving the following types of questions. :

Let's say that there is a column A (department), a column B (employee) and a column C (manager). How can I get all the departments who have only one manager for all their employees? An example is given below:

  department | Employees Manager ------------- + ------------- + ---------- A | | John | Bob A | Sue | Sam B | Gym | Don b Alex | Don si | Jason | Z.C. Greg In this table, the results I get are all sections B and C, because all their employees are managed by the same person (respectively Don and Zee). However, the department will not be repatriated because its employees have many managers.  

Any help or hint will be appreciated.

Such problems usually call for self-union.

After joining the department on your own, filtering tuples where the managers are equal, we can reduce all unwanted yields, which we can only deduct from the original relationship.

Here's how I do it:

T- \ Pi_ {T. Department, T. Ampli, T. Manager} \ left (\ sigma_ {T. Manager / Nibak T 2. Manager / Land T. Department = T 2. Department) First of all, we copy table T , And it is called T2, then take a cross product of T and T2 (left) (\ rho (T, T_2) \ times T \ right) \ right)

. As a result, we select all the rows where T1.Manager / = T2.Manager, but T1.Department = T2.Department, provide us these tips:

  T1.Department | T1.Employees | T1. Manager | T2 Manager | T2 Employees T2 Department -------------- + ------------- + ------------- +---- - ------- + -------------- + -------------- A | | John | Bob | Sam | Sue | A.A. Sue | Sam | Bob | John | A and B. are not present because their T1 managers are always equal to T2. The Manager.  

Then we reduce this result to the original set. answer.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -