使用此查询
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"));
我得到以下结果
如果您想添加全球总和(总和)和键,需要更改哪些内容?
答案 0 :(得分:1)
虽然我没有经过测试,但您应该可以添加另一个字段:
这将为所有年,月和客户增加所有小时数。
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"));
要将GlobalTotal保持至2016年3月,请使用:
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"));
注意 - 我已将hours
重命名为lhours
以避免循环引用。您还应该考虑重命名year
和month
,因为这些是关键词,可能会导致问题
此外,year
和month
会更好,而不是文字。