Distance from the team average
Your task
Given staff with columns name, team, salary, hired and manager, return how far each person salary sits from their own team mean as diff, rounded to two decimal places. Return name and diff, sorted by name ascending.
Examples
pay_vs_team(staff: dataframe) -> dataframeExample 1
Input
pay_vs_team(staff)staff
More rows not shown
| name | team | salary | hired | manager |
|---|---|---|---|---|
| Ada | eng | 120 | 2021-03-01 | Grace |
| Grace | eng | 150 | 2019-06-15 | NULL |
| Linus | eng | 95 | 2022-01-10 | Grace |
| Mel | sales | 80 | 2020-11-05 | Kay |
| Kay | sales | 110 | 2018-02-20 | NULL |
| Ivan | sales | 80 | 2023-07-01 | Kay |
| Jean | design | 105 | 2021-09-30 | NULL |
| Nia | design | 140 | 2022-05-04 | Jean |
Output
More rows not shown
| name | diff |
|---|---|
| Ada | -1.67 |
| Grace | 28.33 |
| Ivan | -18.75 |
| Jean | -17.5 |
| Kay | 11.25 |
| Linus | -26.67 |
| Mel | -18.75 |
| Nia | 17.5 |