Ok, I have a SQL query that I'm using to sum a column and group... This works great however, I also would like to pull a subgroup of that into the Recordset to correspond with the total sum... Is there a way I can do this in the SQL statement?
So for example I have Columns
Apple Green 5
Apple Red 4
Banana Yell 5
Banana Red 3
In my recordset I want to return...
Fruit SumRed TotalSum
Apple 4 9
Banana 3 8
Basically it's a sum/Group and a sum sub-group...
In my example
1)I want to sum by grouping First/Last Name to get the total sum of Actvty_Dur,
2)but I also want to sum into each of those groupings if a KOA_Reason.Reason matches a specific criteria... Say "TRAINING" for example...
If I take out the parts pertaining to KOA_Reason I achieve objective 1, how to I acheive object 2 also?
Here is my SQL statement so far...
So for example I have Columns
Apple Green 5
Apple Red 4
Banana Yell 5
Banana Red 3
In my recordset I want to return...
Fruit SumRed TotalSum
Apple 4 9
Banana 3 8
Basically it's a sum/Group and a sum sub-group...
In my example
1)I want to sum by grouping First/Last Name to get the total sum of Actvty_Dur,
2)but I also want to sum into each of those groupings if a KOA_Reason.Reason matches a specific criteria... Say "TRAINING" for example...
If I take out the parts pertaining to KOA_Reason I achieve objective 1, how to I acheive object 2 also?
Here is my SQL statement so far...
Code:
RSQL = "SELECT KOA_Examiner.CE_First, KOA_Examiner.CE_Last, KOA_Reason.Reason, SUM(KOA_Activity.Actvty_Dur) AS SumOfActvty "
RSQL = RSQL & "FROM KOA_Reason INNER JOIN (KOA_Supervisor INNER JOIN (KOA_Examiner INNER JOIN KOA_Activity ON KOA_Examiner.CE_ID = KOA_Activity.CE_ID) ON KOA_Supervisor.Supervisor_ID = KOA_Examiner.Supervisor_ID) ON KOA_Reason.Reason_ID = KOA_Activity.Reason_ID "
RSQL = RSQL & "WHERE (((KOA_Activity.Activity_Date) Between '" & weekStart & "' AND '" & weekStart + 6 & "') AND ((KOA_Activity.Is_Valid)=1) AND ((KOA_Supervisor.SUP_Alias)='" & ID_ALS & "')) "
RSQL = RSQL & "GROUP BY KOA_Examiner.CE_First, KOA_Examiner.CE_Last, KOA_Reason.Reason;"