Reputation: 685
With this query
SELECT Year, Month, Customer, Cod_user, Int(Sum(hours)) AS hours
FROM T_Att
GROUP BY Year, Mounth, Customer, Cod_user
HAVING (((Year)="2016") AND ((Month)="03") AND ((Customer)="CA"));
I get the following result
If you want to add the global sum (sum) and a key, what needs to change?
Upvotes: 0
Views: 28
Reputation: 19767
Although I haven't tested you should be able to just add another field:
This will add all hours for all years, months and customers.
SELECT Year,
Month,
Customer,
Cod_user,
Int(Sum(hours)) AS lhours,
(
SELECT SUM(hours)
FROM T_Att
) AS GlobalTotal
FROM T_Att
GROUP BY Year, Month, Customer, Cod_user
HAVING (((Year)="2016") AND ((Month)="03") AND ((Customer)="CA"));
To keep the GlobalTotal to March 2016 use:
SELECT Year,
Month,
Customer,
Cod_user,
Int(Sum(hours)) AS lhours,
(
SELECT SUM(hours)
FROM T_Att
WHERE Year = T1.Year AND Month = T1.Month
) AS GlobalTotal
FROM T_Att T1
GROUP BY Year, Month, Customer, Cod_user
HAVING (((Year)="2016") AND ((Month)="03") AND ((Customer)="CA"));
Note - I've renamed hours
to lhours
to avoid a circular reference. You should also consider renaming year
and month
as these are key words and may cause problems.
Also, year
and month
would be better as numbers rather than text.
Upvotes: 1