I am trying to write a query which gives the highest earner (Salary+Bonus) and name of the employee and ID for each department.
I have the following table named Tab1:
ID | Emp | Dep | Salary | Bonus |
---|---|---|---|---|
1 | Mary | X | 50 | |
2 | Adam | Z | 60 | 15 |
3 | Brad | X | 55 | 20 |
4 | Fred | Y | 80 | 30 |
5 | Irene | Y | 90 | |
6 | Alan | Z | 100 | 10 |
I've tried the following query:
SELECT Dep, MAX(Salary)
FROM Tab1
GROUP BY Dep
But this just give me the salary without bonus. I also want to get ID and Emp as a query result.
So the expected result would be:
ID | Emp | Dep | Max_total_salary |
---|---|---|---|
3 | Brad | X | 75 |
4 | Fred | Y | 110 |
6 | Alan | Z | 110 |
I would appreciate any suggestion you have!