mysql - Aggregate Functions on subsets of data based on current row values with SQL -


Hope the title is understandable ...

Assume that I have an employee's The table is:

  id Name | Title | Salary ---------------------------- 1 | Bob | Manager. 15285 2 Joe | Worker | 10250 3 Al. Worker | 11050 4 Paul. Manager. 16025 5 John Worker | 10450  

I have to write a question which will give the above table with an average salary column based on the employee's title:

  ID | Name | Title | Salary Post average -------------------------------------- 1. Bob | Manager. 15285 | 15655 2 Joe Worker | 10250 | 10583 3 Al. Worker | 11050 | 10583 4 Paul. Manager. 16025 15655 5 John. Worker | 10450 | 10583  

I have tried to do this with lines with sub-queries:

  select *, (select from average) Employee E2 where E2.title = e.title) employee  

but I have found that the sub-query is executed first, and there is no knowledge of the table nickname, DE

I am sure that I am very clear, can someone tell me in the right place?

  SELECT e.Id, e.Name, e.Title, e Salary, G. From Employee E, (SELECT e.Title, avg (salary) E-Group by PosAvg employee) where e Title = G. Title  

Comments