Average with condition
I am trying to figure out how to calculate the exact mean of a variable. I currently have this request: (simplified):
select ID , Group_ID, Chargeability,Job_No_, Group_Charg FROM Data1
ID Group ID Chargeability Job No_ Group Chargeability
1 a 90 c1 88.11
1 a 90 c2 88.11
1 a 90 c3 88.11
1 a 90 c4 88.11
2 a 85.6 c8 88.11
2 a 85.6 c17 88.11
2 a 85.6 c6 88.11
The average is not the actual value. The charge is fixed for each ID, so the average shouldn't take into account the number of rows per ID, because this is just a value replacement, since we have many jobs per ID.
Ie I would like to have Group_chargeability
= (90 + 85.6) / 2 instead of (90 * 4) + (85.6 * 3) / 7 as is currently done.
A query consists of several subqueries, some of which also call a function. This is why I cannot use the group to try and solve the problem I have.
+3
source to share