Access 2010 Sum错误结果

时间:2016-05-16 13:01:45

标签: int sum access

这是我的问题。

第一步。 我将列HH(别名 SUM_Original_values )加起来,得到419.这个结果是正确的。 (见下图)

enter image description here

第二步。 我只想取HH列的 INT 值,得到417.这个结果是正确的。 (见下图)

enter image description here

第三步。 我想创建一个列 Global_Int_Sum_HH (416),但此值与 Int_Sum_HH (417)不同

enter image description here

为什么结果不同?

这是查询

SELECT 
 Year, 
 Month, 
 Customer,
 User, 
 Int(Sum(HH)) AS Int_Sum_HH, 

(
SELECT  (int(sum(int(HH)))) AS Global_Int_Sum_HH
FROM T_Att
HAVING (((Year)="2016") AND ((month)="03") AND ((Customer)="FC"));
) AS Global_Int_Sum_HH, 

Customer + Str(Global_Int_Sum_HH) AS [KEY]

FROM T_Att

GROUP BY Year, Month, Customer, User
HAVING (((Year)="2016") AND ((Month)="03") AND ((Customer)="FC"));

1 个答案:

答案 0 :(得分:1)

在我看来,您的操作顺序不一致。

在一个实例中,您int sum,而在第二个实例中sum int

SELECT 
 Year, 
 Month, 
 Customer,
 User, 
 Sum(Int(HH)) AS Int_Sum_HH, 
-- ^ changed order of events to match sub-query
(
-- v removed redundant int()
SELECT  sum(int(HH)) AS Global_Int_Sum_HH
FROM T_Att
HAVING (((Year)="2016") AND ((month)="03") AND ((Customer)="FC"));
) AS Global_Int_Sum_HH, 

Customer + Str(Global_Int_Sum_HH) AS [KEY]

FROM T_Att

GROUP BY Year, Month, Customer, User
HAVING (((Year)="2016") AND ((Month)="03") AND ((Customer)="FC"));

上述调整将使两个值的“正确”答案= 416。如果您要将操作顺序更改为Int(Sum(HH)),则Global_Int_Sum_HH值将等于419,而Int_Sum_HH列将改为417