+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Doc | varchar(5) | NO | PRI | NULL | |
| Name | varchar(20)| NO | | NULL | |
| Salary | varchar(7) | NO | | NULL | |
| City | varchar(10)| NO | | NULL | |
| Boss | varchar(5) | YES| | NULL | |
+----------+-------------+------+-----+---------+-------+
In this table theres Doc (which is document and the primary key) of the employee, the name of the employee, the salary of the employee, the city in which the employee is at, and the boss which is the Doc.
so i put some info in and it looks like this:
+-------+----------+---------+----------+-------+
| Doc | Name | Salary | City | Boss |
+-------+----------+---------+----------+-------+
| 10305 | Joey | 700 | NYC | NULL |
| 10244 | John | 900 | Boston | 10305 |
| 35357 | Mary | 600 | Boston | 10305 |
| 90012 | Becky | 650 | Miami | 35357 |
| 10235 | Jose | 400 | LA | 35357 |
| 95632 | Anthony | 900 | Miami | 35357 |
| 12345 | Mateo | 500 | NYC | 10305 |
+-------+----------+---------+------------+-------+
Joey is the boss of:
-John
-Mary
-Mateo
Mary is the boss
-becky
-Jose
-anthony
I have to average the salary of the people that work for the same boss, that means and average of John, mary and mateo since they work for joey and another of becky, jose and anthony since they are mary's employee.
Ok now when i get the average of each work group, now i have to select the persons in each team that earns lower than the average salary of that work group. How do i do this?
I tried:
SELECT T2.min(salary), T1.min(salary) from employees T1 INNER JOIN employees T2 ON T1.Doc = T2.Boss WHERE avg(t2.salary) AND avg(t1.salary);
but no luck...
THANKSSSS