mysql - Find the Average salary deviation for an employee within department -
i have list of employees work within set of teams. trying figure out each year difference each employee’s salary department’s average. have been looking @ standard deviations i’m little stuck if need have sub select achieve this.
the table looks like:
i not have code show because stuck on aliases.
just break down task in simple tasks. let's find average salaries first:
select teamid, `year`, avg(salary) avgsal employees group teamid, `year`
now, difference need subtract employee's salary average:
select e.employeeid, e.salary, a.avgsal, e.salary - a.avgsal diff employees e inner join ( select teamid, `year`, avg(salary) avgsal employees group teamid, `year` ) on a.teamid = e.teamid , a.`year` = e.`year`
Comments
Post a Comment