I have three tables that will be used in the query:
Departments:
DepartmentID - PK
DepartmentName
Earnings:
EarningID - PK
PersonID
EarningValue
People:
PersonID - PK
DepartmentID
Surname
Name
I need to make a query that will return 4 columns:
- DepartmentName
- Surname of Person
- Sum of all Earnings of Person
- Sum of all Earnings of Department
I was reading about ROLLUP, CUBE, and GROUPING SETS clauses, but i dont have idea how to use it here. An important thing is that i cannot use OVER (PARTITION
I think something like this would do the trick. (Assuming SQL Server)
Basically, you sum them up separately, and then join them together after that.